home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / batchart.zip / BATCH.DOC next >
Text File  |  1988-04-29  |  126KB  |  3,169 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.             
  8.             George Campbell
  9.             1472 Sixth St.
  10.             Los Osos, CA  93402
  11.             
  12.             
  13.             
  14.             
  15.             
  16.             
  17.                          The Power of PC/MS-DOS Batch Files
  18.                                          by
  19.                                   George Campbell
  20.                                           
  21.                               Part 1: Getting Started
  22.             
  23.             
  24.             One of the keys to getting the most from your IBM-compatible
  25.             computer is learning to make the most of the operating
  26.             system.  PC/MS-DOS, while not as simple to learn as the
  27.             operating systems for some other computers, has the
  28.             potential to let you customize your computing and increase
  29.             your productivity.
  30.             
  31.             When Microsoft designed the original PC/MS-DOS, the personal
  32.             computer was still something of an unknown quantity.  Few
  33.             people anticipated the millions of personal computers that
  34.             would be sold.  Fortunately for users, PC/MS-DOS included a
  35.             powerful capability: batch processing.
  36.             
  37.             This series of articles will explore the depths of PC/MS-DOS
  38.             batch processing, teaching you how to automate many of the
  39.             functions of your PC.  You'll also learn how to use batch
  40.             files to make your PC do things you never thought possible.
  41.             
  42.             BATCH FILE BASICS
  43.             
  44.             There are three types of programs that PC/MS-DOS can run
  45.             directly.  You are already familiar with two of them.  Files
  46.             with the extensions .COM and .EXE run when you enter the
  47.             filename at your system prompt.  Batch files, with the
  48.             extension, .BAT, are the third type.
  49.             
  50.             A batch file is nothing more than a series of DOS commands,
  51.             separated by carriage returns.  When you enter the name of
  52.             the batch file, DOS carries out the commands, one at a time.
  53.             
  54.             Once a batch file is running, you can stop it by holding
  55.             down the <Ctrl> key while you press the <Break> key.  If you
  56.             do this, a message will appear on the screen: Terminate
  57.             batch job (Y/N)?  If you press a Y, the batch file will
  58.             abort.  Pressing N continues the batch file's operation.
  59.             
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.                                              Page 2
  71.  
  72.  
  73.             You can use any DOS command in a batch file, from simple
  74.             ones like COPY to commands seldom used, like ASSIGN.  When
  75.             you call a batch file by entering its file name, PC/MS-DOS
  76.             opens the file, and carries out the first command.  Once the
  77.             operation of that command is completed, the system prompt
  78.             (A>, C>, etc.) reappears, and the next command in the batch
  79.             file executes automatically.
  80.             
  81.             There is no limit to the length of a batch file.  The
  82.             computer will continue to carry out the commands until it
  83.             reaches the end of the file.
  84.             
  85.             CREATING BATCH FILES
  86.             
  87.             There are five basic requirements for the structure of any
  88.             batch file:
  89.             
  90.             1.  It must be a pure ASCII file, meaning that no characters
  91.             other than the commands you give, plus carriage returns, can
  92.             be used in the file.
  93.             
  94.             2. The filename can be any legal filename, but cannot have
  95.             the same name as a .COM or .EXE file in the same directory,
  96.             or the same name as any DOS internal command, such as COPY
  97.             or DIR.
  98.             
  99.             3.  It must have the extension .BAT.
  100.             
  101.             4.  The file must have an end-of-file marker following the
  102.             last command in the file.
  103.             
  104.             5. Each command must be on a separate line in the batch
  105.             file, separated from adjacent commands by a carriage return.
  106.             
  107.             Creating an actual batch file is simple.  There are two
  108.             basic methods I recommend.  Each has its advantages and
  109.             disadvantages.
  110.             
  111.             The first method uses the DOS COPY command.  Use this method
  112.             for creating short, simple batch files.  First, give the
  113.             command: COPY CON [DRIVE][PATH][FILENAME].  Here's a sample
  114.             command:
  115.             
  116.             COPY CON C:\BATCH\STARTUP.BAT <Enter>
  117.             
  118.             This command will create the file, STARTUP.BAT, in the
  119.             \BATCH directory in drive C:.  When you press <Enter> the
  120.             cursor will move to the next line on the screen and you can
  121.             begin writing your batch file.
  122.             
  123.             Type in the first command in your series of commands.  You
  124.             can correct your spelling by backspacing and retyping, as
  125.             long as the cursor is on the current line.  When the line is
  126.             correct, press <Enter> to move the cursor to the next line.
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.                                              Page 3
  137.  
  138.  
  139.             
  140.             Now type in additional commands, as needed for your batch
  141.             file, following each line by pressing <Enter>.  This adds a
  142.             carriage return character to the end of the line, telling
  143.             PC/MS-DOS to carry out the command on that line.
  144.             
  145.             Once you have typed in all the commands to be used in that
  146.             particular batch file, press <Enter> once more at the end of
  147.             the last line.  Now press <F6> or hold down the <Ctrl> key
  148.             while you press the <Z> key.  Either operation will place an
  149.             end-of-file character in your file.  Press <Enter> again and
  150.             the computer will write the file to the disk.
  151.             
  152.             Test this procedure by creating a batch file which displays
  153.             a directory.  Follow the steps below to create this file in
  154.             the current drive and directory.  At the system prompt,
  155.             type:
  156.             
  157.             COPY CON D.BAT <Enter>
  158.             DIR <Enter>
  159.             <F6> or <Ctrl>+<Z> <Enter>
  160.             
  161.             Your drive light will come on, and the file will be written
  162.             to disk.  Now, check your work and test the file. Press the
  163.             <D> key, then press <Enter>.  You should see a directory on
  164.             your monitor.  Notice that you have simplified the command
  165.             which displays a directory.  Now you only have to type a
  166.             single letter, instead of three.
  167.             
  168.             While the COPY CON method works fine, it's not as convenient
  169.             for longer batch files which might contain many commands.
  170.             If you make a mistake with the COPY CON method, there is no
  171.             way to fix it.  You have to retype the entire batch file.
  172.             For this reason, use this method only for short, simple
  173.             files.
  174.             
  175.             When you need to create a longer batch file, use a text
  176.             editor.  Just about any text editor or word processing
  177.             program will work.  The only requirement is that the editor
  178.             must be able to save pure ASCII files.
  179.             
  180.             If you use PC-WRITE, your batch files will automatically be
  181.             saved in ASCII.  WordStar users must open batch files in the
  182.             Non-Document mode.  Microsoft Word users can create batch
  183.             files, then save them in ASCII format by choosing the "No"
  184.             option in the "Transfer Save" menu.  Check the user's manual
  185.             for your word processor for its procedures.
  186.             
  187.             If you're not sure about the method your editor uses, try
  188.             creating a batch file.  Save it, then exit the program and
  189.             use the TYPE command to display the file on your monitor.
  190.             If you see your file, without any extra characters on the
  191.             screen, you know that it is pure ASCII, and can be used as a
  192.             batch file.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.                                              Page 4
  203.  
  204.  
  205.             
  206.             Whichever method you use, remember to use the .BAT extension
  207.             and don't give your file a name which would conflict with
  208.             another executable file in its directory.  If your batch
  209.             file has a name which is the same as a .COM or .EXE file, or
  210.             a DOS internal command, it simply won't execute.
  211.             
  212.             A SPECIAL BATCH FILE: AUTOEXEC.BAT
  213.             
  214.             When you boot up your computer, several things happen.
  215.             First, the ROM BIOS in your PC checks the system's memory,
  216.             then looks for a disk in drive A: or for a hard disk drive.
  217.             It then loads the system files from the disk into memory.
  218.             These files include COMMAND.COM plus two hidden files.  One
  219.             these files are loaded, it looks for a file called
  220.             CONFIG.SYS and carries out any functions contained in that
  221.             file.
  222.             
  223.             Finally, it looks for a batch file named AUTOEXEC.BAT. If
  224.             the file exists, PC/MS-DOS carries out the commands in that
  225.             file.  If there is no AUTOEXEC.BAT file, you see the
  226.             standard request for the current date and time on your
  227.             screen.
  228.             
  229.             An AUTOEXEC.BAT file can contain any commands you want to
  230.             use every time you boot your PC.  Suppose, for example that
  231.             you always wanted to start the program, Microsoft Word, when
  232.             you turned on your PC.  Just create a batch file, named
  233.             AUTOEXEC.BAT on your boot disk, or in the root directory of
  234.             your hard disk, using one of the techniques above.  This
  235.             file has only one line:
  236.             
  237.             WORD
  238.             
  239.             Naturally, you could substitute the command you use to start
  240.             any program you choose.  When PC/MS-DOS finds an
  241.             AUTOEXEC.BAT file, it bypasses the date and time sequence
  242.             and immediately carries out the command in the file.
  243.             
  244.             Now, suppose you need to change directories on your hard
  245.             disk before starting the program.  Using Word as an example
  246.             again, here's a sample file:
  247.             
  248.             CD WP
  249.             WORD
  250.             
  251.             This time, the AUTOEXEC.BAT file tells the PC to change to
  252.             the \WP directory, then start Microsoft Word.  It's easy to
  253.             see how you could adapt this to your own needs.
  254.             
  255.             Now, let's add something else.  Many users install memory-
  256.             resident programs before loading an application.  SideKick
  257.             is a popular memory resident program.  Here's a sample file:
  258.             
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.                                              Page 5
  269.  
  270.  
  271.             CD UTILITY
  272.             SK
  273.             CD \WP
  274.             WORD
  275.             
  276.             Line-by-line, here's what this AUTOEXEC.BAT file does:
  277.             
  278.             1. Changes to the \UTILITY directory on your hard disk.
  279.             2. Loads SideKick.
  280.             3. Changes to the \WP directory.
  281.             4. Loads Microsoft Word.
  282.             
  283.             Once again, you can substitute any directory name or command
  284.             for the ones used in this sample file.  Try creating your
  285.             own AUTOEXEC.BAT file, using commands you select.
  286.             
  287.             OTHER SIMPLE BATCH FILES
  288.             
  289.             Batch files can be extremely useful in saving keystrokes.  I
  290.             often create them just to avoid typing long filenames or
  291.             commands.  Let's look at some ways to help yourself out with
  292.             batch files.
  293.             
  294.             When you looked at the section on AUTOEXEC.BAT files, you
  295.             learned how to start a program automatically when you booted
  296.             your system.  You can use other batch files to start
  297.             programs with just a keystroke or two.  Let's keep using
  298.             Microsoft Word as an example.
  299.             
  300.             As before, I'll assume that we're working with a hard disk.
  301.             Floppy disk users can just leave out the directory change
  302.             commands in their batch files.  Here's a simple batch file,
  303.             named W.BAT that starts the program with a single keystroke.
  304.             
  305.             CD WP
  306.             WORD
  307.             
  308.             Now, when you use this file by typing a <W> and pressing
  309.             <Enter>, Microsoft Word will run.  When you exit from the
  310.             program, however, you'll still be in the \WP directory on
  311.             your hard disk.  Add a third line to return you to the root
  312.             directory when you exit Word.  W.BAT will look like this:
  313.             
  314.             CD WP
  315.             WORD
  316.             CD\
  317.             
  318.             When you leave Word, PC/MS-DOS knows that the batch file
  319.             still has another command, so it returns to it and carries
  320.             out the next command in the file.
  321.             
  322.             Suppose that you normally move to another program after
  323.             exiting Word.  You can have your batch file do this
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.                                              Page 6
  335.  
  336.  
  337.             automatically.  Let's try starting Lotus 123 after exiting
  338.             Word.  Here's a batch file to do just that:
  339.             
  340.             CD WP
  341.             WORD
  342.             CD \LOTUS
  343.             123
  344.             CD\
  345.             
  346.             You can easily see how many keystrokes are saved by using a
  347.             batch file instead of typing in all the commands.  And
  348.             that's just the beginning.
  349.             
  350.             Batch files are actually simple computer programs.  By
  351.             writing these files, you are learning simple computer
  352.             programming.
  353.             
  354.             In this first part of the series, you've learned how to
  355.             create simple batch files which save keystrokes.  But batch
  356.             files can do much more.  Using the full power of PC/MS-DOS
  357.             batch files, you can actually create real programs.
  358.             
  359.             In future parts of this series, you will learn how to create
  360.             menus to help you or others run a PC.  You will also learn
  361.             how you can dial your phone using batch files, create
  362.             software installation programs, control your printer, and
  363.             perform many other operations with a single keystroke.
  364.             
  365.             More than that, batch files can create systems to protect
  366.             your PC and its files from prying eyes and fingers.  You can
  367.             even create a database system with batch files which will
  368.             let you have almost instant access to any information.
  369.             
  370.             Batch files can use a number of special commands to teach
  371.             your PC to do things you never thought possible.  Best of
  372.             all, they are easy to use.
  373.             
  374.                               Part 2: Batch File Menus
  375.             
  376.             
  377.             Whether you use a hard disk or floppies on your PC, learning
  378.             to create a menu system can save valuable minutes and make
  379.             your PC easier to use.  In addition, if you help other
  380.             people with their computers, installing a menu system can
  381.             help you avoid constant phone calls for help.
  382.             
  383.             Batch files are an ideal method for creating menus.  Batch
  384.             file menu systems are easy to write, easy to change, and
  385.             extremely powerful.  You can incorporate as many features
  386.             into your menu as you like, allowing you or anyone else to
  387.             access programs with a single keystroke.
  388.             
  389.             USING THE ECHO COMMAND
  390.             
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.                                              Page 7
  401.  
  402.  
  403.             To create a menu system, you need to be able to write
  404.             information on the screen with your batch file.  PC/MS DOS
  405.             gives you a command which makes this easy: ECHO.  Here's how
  406.             it works:
  407.             
  408.             You can use the ECHO command in two ways.  Each uses a
  409.             different format.  The first format allows you to tell your
  410.             PC whether or not you want to see the commands in your batch
  411.             file listed on the screen.  Usually you don't, and the
  412.             command used to disable screen writing is: ECHO OFF
  413.             
  414.             When you include this command in a batch file, commands in
  415.             that file will not appear as they are executed.  This makes
  416.             for a cleaner screen appearance.  To turn the ECHO function
  417.             back on, just include the command: ECHO ON.
  418.             
  419.             The second format for the ECHO command allows you to place
  420.             messages on the screen.  You'll use this function to write
  421.             your menu on the monitor.  The syntax is: ECHO  [message]
  422.             
  423.             For example, to write the line "Master Menu" on the screen,
  424.             include the command: ECHO Master Menu as a line in your
  425.             batch file.  You can control the position of the message by
  426.             including spaces.  If you want to center a line on the
  427.             screen, simply subtract the number of characters in your
  428.             message from 80, then divide the result in half.  Place that
  429.             number of spaces in front of your message.
  430.             
  431.             To make a menu or other text screen attractive, you need to
  432.             be able to add blank lines.  The ECHO command can do this as
  433.             well, but there's a trick to it.
  434.             
  435.             Until DOS Version 3.3 appeared, creating blank lines wasn't
  436.             simple.  Instead of simply following the ECHO command with a
  437.             space, which creates a blank line in DOS 3.3, earlier
  438.             versions of DOS require a special method.  This method will
  439.             work with any version of DOS from 2.0 to 3.3.
  440.             
  441.             To create a blank line, place the ECHO command on a line in
  442.             your batch file.  Next press the space bar once, then hold
  443.             down the <Alt> key while you type 255 on the number pad.
  444.             The numbers at the top of the keyboard won't work.  Doing
  445.             this inserts the ASCII character number 255, which is a
  446.             blank character.  This fools DOS into thinking that there is
  447.             a message, and creates a blank line on the screen.
  448.             
  449.             This method works with the COPY CON method for creating
  450.             batch files, and with most word processors.  If your text
  451.             editor doesn't support this function, either use another
  452.             editor or simulate a blank line by inserting a period
  453.             following the ECHO command.
  454.             
  455.             One final note on the ECHO command:  You cannot use the DOS
  456.             redirection characters (< and >) in an ECHO statement. If
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.                                              Page 8
  467.  
  468.  
  469.             you do, the error message, "Bad command or filename," will
  470.             appear.
  471.             
  472.             CREATING THE MENU SYSTEM
  473.             
  474.             
  475.             Now that you know how to use the ECHO command to create
  476.             messages on the screen, you're ready to create a menu.  For
  477.             the purposes of this article, let's assume that you want
  478.             your menu to call Microsoft Word, Lotus 123, QMODEM, and the
  479.             game ROGUE.  You can also include a menu choice to return to
  480.             DOS in the menu.  Naturally, you will use the programs on
  481.             your disk as replacements for those in this sample program.
  482.             
  483.             Using the COPY CON command as described in the first part of
  484.             this series, or your favorite text editor, create the file
  485.             MENU.BAT in the root directory of your hard disk or on a
  486.             floppy disk. Don't include the comments in parentheses, and
  487.             substitute names of programs.
  488.             
  489.             ECHO OFF   (Turns off the echoing of batch file commands)
  490.             CLS        (Clears the screen)
  491.             ECHO [Alt-255] (Create a blank line as described above. Use
  492.             as many of these blank lines as you like.)
  493.             ECHO[35 spaces]Master Menu
  494.             ECHO [Alt-255]
  495.             ECHO[32 spaces]Do you want to:
  496.             ECHO [Alt-255]
  497.             ECHO[15 spaces]1. Use your word processor?
  498.             ECHO[15 spaces]2. Use Lotus 123?
  499.             ECHO[15 spaces]3. Use your communications program?
  500.             ECHO[15 spaces]4. Play Rogue?
  501.             ECHO[15 spaces]5. Return to the DOS prompt?
  502.             ECHO [Alt-255]
  503.             ECHO At the DOS prompt, type the number of your selection
  504.             ECHO and press [Enter].
  505.             
  506.             Be sure to place a carriage return at the end of the last
  507.             line of the file, then save it in ASCII format, or press
  508.             <F6> if you are use the COPY CON command.  To call your menu
  509.             screen when you boot your computer, include the command,
  510.             MENU, as the last line of your AUTOEXEC.BAT file.
  511.             
  512.             Once again, you can customize this menu screen any way you
  513.             like.  Include as many menu choices as you need, and insert
  514.             blank lines and spaces to make the screen as attractive as
  515.             possible.
  516.             
  517.             When MENU.BAT is executed, it will write the menu on the
  518.             monitor, then the system prompt will reappear.
  519.             
  520.             EXECUTING YOUR MENU CHOICES
  521.             
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.                                              Page 9
  533.  
  534.  
  535.             Once you've written the MENU.BAT file, you need to write
  536.             individual batch files for each menu choice.  These files
  537.             will call a program when you or the user enters a menu
  538.             selection.
  539.             
  540.             Name the files to match your menu selections.  In the sample
  541.             menu presented here, the files would be named 1.BAT, 2.BAT,
  542.             and so on.  Each of these files will contain the commands
  543.             needed to call the program.  Here's 1.BAT:
  544.             
  545.             ECHO OFF  (This line turns off the ECHO function)
  546.             CLS       (Clear the screen)
  547.             CD WP     (Change directories...not needed for floppies)
  548.             WORD      (Call Microsoft Word)
  549.             CD\       (Change to the root directory after quitting Word)
  550.             MENU      (Return to the menu)
  551.             
  552.             Naturally, you'll include the commands needed to perform the
  553.             functions in your menu, rather than the ones used here.
  554.             Floppy disk users can ignore the CD commands in their batch
  555.             files.
  556.             
  557.             Create a separate file for each menu choice.  The last menu
  558.             choice, which you should include in any menu system, takes
  559.             the user to the DOS prompt, allowing him or her to use the
  560.             computer for purposes not included in the menu.  Here's a
  561.             sample, 5.BAT, for this menu:
  562.             
  563.             ECHO OFF
  564.             CLS
  565.             CD\
  566.             
  567.             This file will return the user to a clean screen and the
  568.             system prompt.
  569.             
  570.             REFINING YOUR MENU SYSTEM
  571.             
  572.             Generating screens with the ECHO command is only one of the
  573.             ways you can write information on the monitor.  If you
  574.             create a complex screen, you'll notice that when the batch
  575.             file executes, the screen appears rather slowly.  This is
  576.             one of the drawbacks to the ECHO command.
  577.             
  578.             There's an alternative to the ECHO command for screen
  579.             generation.  Since you can use any DOS command in your batch
  580.             files, you can use the TYPE command to place text on the
  581.             screen.
  582.             
  583.             To do this, create your screen with your text editor or word
  584.             processor.  Save the screen as an ASCII file, then call it
  585.             with the TYPE command in your MENU.BAT file.  The menu will
  586.             appear much faster, particularly if it is a complex one.
  587.             You can even include boxes and other special characters if
  588.             your text editor supports extended ASCII characters.
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.                                              Page 10
  599.  
  600.  
  601.             
  602.             Keep your text screens shorter than 23 lines to prevent
  603.             unwanted scrolling when the TYPE command lists the file on
  604.             the monitor.
  605.             
  606.             Here is a MENU.BAT file which performs the same function as
  607.             the previous one, but this time it calls a screen created
  608.             with a word processor.  The screen file is named MENU.DOC.
  609.             
  610.             ECHO OFF
  611.             CLS
  612.             TYPE MENU.DOC
  613.             
  614.             This file is obviously much shorter, and the menu screen
  615.             will appear very quickly on the monitor.  The individual
  616.             files which call the programs will be exactly the same.
  617.             
  618.             In many cases, you may want to eliminate the DOS prompt
  619.             entirely from your menu.  That's easy, using the PROMPT
  620.             command.  PC/MS-DOS allows you to customize a prompt to suit
  621.             your needs.  As an example, you could replace the last two
  622.             lines in the original MENU.BAT file shown above with the
  623.             following line:
  624.             
  625.             PROMPT Type your selection and press [Enter]:
  626.             
  627.             This line would replace the normal A> or C> prompt with the
  628.             text following the PROMPT command.  The normal cursor
  629.             appears at the end of the new prompt.
  630.             
  631.             You can even eliminate the prompt completely.  Do this by
  632.             using the same <Alt>-255 keystroke combination used with the
  633.             ECHO command.  Just type PROMPT, then hold down the <Alt>
  634.             key while you type 255 on the number pad.
  635.             
  636.             If you turn off or change the prompt, however, be sure to
  637.             restore it to its original form in the menu selection file
  638.             which returns the user to DOS.  To do this, simply add a
  639.             line to the batch file.  This line should contain the
  640.             command, PROMPT, and nothing else, and will restore the
  641.             normal system prompt.
  642.             
  643.             MULTI-USER MENUS
  644.             
  645.             The menu-creation process can be further refined for
  646.             computers used by more than one person.  In many cases, you
  647.             want to restrict certain users to a specific group of
  648.             programs.  This technique can even be used to create a
  649.             simple password system.  It's not extremely secure, but will
  650.             limit unsophisticated users to a limited group of programs.
  651.             Here's how to create this type of system.
  652.             
  653.             First, create a batch file called PASSWORD.BAT.  Here's a
  654.             sample:
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.                                              Page 11
  665.  
  666.  
  667.             
  668.             ECHO OFF
  669.             CLS
  670.             PROMPT Please enter your password:
  671.             
  672.             Call this file from the AUTOEXEC.BAT file, after loading any
  673.             memory-resident programs, and performing any other start-up
  674.             functions.  The screen will clear, and the prompt will ask
  675.             for the user's password.  If security isn't important, you
  676.             could ask for the user's name instead.
  677.             
  678.             Now, create a menu for each user, giving it a filename which
  679.             matches the password or name the user will enter.  Using the
  680.             techniques described above, you can limit access to a
  681.             specific list of programs for each user.  In this case,
  682.             however, don't include a menu choice which exits to DOS.
  683.             Instead, make the last menu choice call the PASSWORD.BAT
  684.             file.  If you need to change a user's password, simply
  685.             change the name of the batch file which calls that user's
  686.             menu.
  687.             
  688.             If the user needs to use certain DOS commands, such as COPY,
  689.             DELETE, or BACKUP, you can allow the use of a limited set of
  690.             DOS commands by including them in a directory, then changing
  691.             to that directory with a batch file called from the user's
  692.             menu.
  693.             
  694.             Once again, this system is not perfectly secure.  Any user
  695.             sophisticated enough to use the <Ctrl>+<Break> combination
  696.             can exit to DOS.  When he or she does that, however, the
  697.             prompt will still ask for a password.
  698.             
  699.             If you use DOS 3.0 or a later version, you can add to the
  700.             system's security.  Use any utility program, such as Norton
  701.             Utilities or PC-Tools to change your password batch files to
  702.             hidden files.  Anyone doing a directory will not see the
  703.             files on the screen, but DOS knows they are there and will
  704.             execute them normally.  Earlier versions of DOS cannot
  705.             execute hidden files.
  706.             
  707.             As the installer or main user of a multi-user PC, you can
  708.             bypass the password system by having a batch file with your
  709.             password simply reset the prompt and exit to DOS.  This will
  710.             allow you or another user full access to the system.
  711.             
  712.             The next part of this series will introduce a number of
  713.             other DOS commands which are especially useful in batch
  714.             operations.  Using these commands, you will gain even more
  715.             control over your PC and its peripherals, increasing the
  716.             power of your batch files.
  717.             
  718.                                           
  719.             
  720.             
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.                                              Page 12
  731.  
  732.  
  733.                                           
  734.                       Part 3: Expanding Batch File Operations
  735.             
  736.             If you're like most PC/MS-DOS users, you use a few basic DOS
  737.             commands regularly.  Other commands you may not use,
  738.             however, have the power to make your PC even more useful and
  739.             efficient.
  740.             
  741.             Including these commands in your batch files can add new
  742.             flexibility and let you control your PC better, making it an
  743.             even more powerful tool.  Here are some little-known DOS
  744.             commands especially suited for batch files.
  745.             
  746.             The ASSIGN Command
  747.             
  748.             This very powerful DOS command tells your PC to send all
  749.             calls for one disk drive to another.  Programs often look
  750.             for data on a specific drive.  This is especially true with
  751.             public domain and shareware programs.
  752.             
  753.             These programs assume that the disk containing data files is
  754.             in drive A: or B:.  Hard disk users often have difficulties
  755.             running these programs.  When the program wants to open a
  756.             file on drive A: and that file is on drive C:, the program
  757.             can't find the file and often just exits to DOS.
  758.             
  759.             Using ASSIGN, you can tell your PC to look on drive C: for
  760.             files, no matter what the program tells it to do.  Here's
  761.             the format for that command:
  762.             
  763.             ASSIGN [D1 = D2]
  764.             
  765.             To send all calls for drive A: to drive C:, the command
  766.             would be:
  767.             
  768.             ASSIGN A = C
  769.             
  770.             There are a few restrictions to the use of ASSIGN.  You
  771.             can't use it while using the PRINT command.  In addition,
  772.             FORMAT will not run when ASSIGN is in use.  Notice, too,
  773.             that colons aren't used after the drive names when you use
  774.             the ASSIGN command.
  775.             
  776.             After using this command, you must turn off the drive
  777.             assignment before going on to other computer operations.
  778.             Simply issue the command, ASSIGN, without any drive
  779.             parameters. You can do this automatically in a batch file.
  780.             
  781.             For an example, let's assume you want to run the game
  782.             program, CASTLE, which looks for a data file in drive A:.
  783.             You have CASTLE and its data file on Drive C:, which would
  784.             abort the program when it couldn't find the data file.
  785.             Here's a batch file to solve the problem:
  786.             
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.                                              Page 13
  797.  
  798.  
  799.             ASSIGN A = C
  800.             CASTLE
  801.             ASSIGN
  802.             
  803.             This file, which you might call PLAY.BAT, solves the
  804.             problem, and returns you to the normal configuration when
  805.             you exit from the game.
  806.             
  807.             You can also use the ASSIGN command to lock out your hard
  808.             disk if you are testing a questionable program.  Just give
  809.             the command, ASSIGN C = A, and the PC won't try to write any
  810.             data to your hard disk.  Just remember to get rid of the
  811.             assignment before resuming normal operations.
  812.             
  813.             The ECHO Command
  814.             
  815.             In part 1 of this series, you learned to use this command to
  816.             display screen messages.  ECHO can perform other functions,
  817.             however, which are useful in batch files.
  818.             
  819.             For example, you might want to make the computer beep at
  820.             some point during the execution of a batch file.  To do
  821.             this, include the following command as a line in your file:
  822.             
  823.             ECHO ^G
  824.             
  825.             Type ECHO, press the space bar once, then hold down the
  826.             <Ctrl> key while you press the <G> key.  This adds a
  827.             character, ASCII number 7, to your command.  Whenever this
  828.             command executes, you hear the familiar beep.
  829.             
  830.             You can also use the ECHO command with the DOS redirection
  831.             characters < and > to send text to your printer or to your
  832.             serial ports.
  833.             
  834.             Here's a good example:  You may need to print labels with
  835.             your return address on them.  It's easy, using a batch file
  836.             containing the following lines:
  837.             
  838.             ECHO Your Name >PRN
  839.             ECHO 123 Your Street >PRN
  840.             ECHO Anytown, Anystate  12345 >PRN
  841.             
  842.             Add blank lines before and after the text.  Adjust the
  843.             number of blank lines to suit your printer and the labels
  844.             you use.  You'll have to experiment to get it just right.
  845.             
  846.             Call this batch file RETURN.BAT, or any other name you like.
  847.             Whenever you execute the file, it will print your return
  848.             address, saving you from starting your word processor to
  849.             create an address label.  You can also create similar files
  850.             for other addresses.
  851.             
  852.             The MODE Command
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.                                              Page 14
  863.  
  864.  
  865.             
  866.             The MODE command allows you to control your monitor, your
  867.             serial ports, and your printer.  The command is very seldom
  868.             used, due to its hard-to-remember syntax.  This makes it a
  869.             natural for batch files.
  870.             
  871.             To use the MODE command in batch files, the DOS utility
  872.             MODE.COM or MODE.EXE must be in your current PATH, or on the
  873.             floppy disk containing your batch file.  If DOS can't find
  874.             the program, an error message will appear on your monitor.
  875.             
  876.             If your PC has a CGA or EGA display adapter, you can use the
  877.             MODE command to change from one display mode to another.  If
  878.             you want to change from the normal mode to a forty-character
  879.             color screen, include the following line in a batch file:
  880.             
  881.             MODE CO40
  882.             
  883.             Check your DOS manual for other screen modes.  You can
  884.             include this command in a long batch file, or use it alone
  885.             in a file called 40.BAT.
  886.             
  887.             The syntax for the MODE command format used to set up your
  888.             serial port is very complex.  Using a batch file, you can
  889.             avoid having to memorize this syntax.  To set your COM1:
  890.             port to 1200 baud, with even parity, seven data bits, and
  891.             one stop bit, just use the following line in any batch file:
  892.             
  893.             MODE COM1: 1200,E,7,1
  894.             
  895.             Later, you will learn how to incorporate this command line
  896.             in a batch file telephone dialing system.
  897.             
  898.             Many users have a printer connected to a serial port.  In
  899.             this case, DOS needs to know where the printer is, since it
  900.             assumes that the printer is connected to LPT1:. Include the
  901.             following line in your AUTOEXEC.BAT file and your PC will
  902.             automatically send all printer output to COM1:.
  903.             
  904.             MODE LPT1: = COM1:
  905.             
  906.             
  907.             If your printer, on the other hand, is connected to LPT2:,
  908.             the second parallel port, use the following line:
  909.             
  910.             MODE LPT1: = LPT2:
  911.             
  912.             Finally, you can use the MODE command to set your printer's
  913.             mode of operations, controlling the number of characters per
  914.             line, the number of lines per inch, and whether or not you
  915.             want the computer to keep trying if the printer sends an
  916.             error message to the computer.  Here's the syntax:
  917.             
  918.             MODE LPT#: [characters\line], [lines/inch], [P]
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.                                              Page 15
  929.  
  930.  
  931.             
  932.             Following this syntax, to set your printer for 80 characters
  933.             per line, 8 lines per inch, and to retry on errors, use the
  934.             following command in a batch file:
  935.             
  936.             MODE LPT1: 80,8,P
  937.             
  938.             The PAUSE Command
  939.             
  940.             Many time, during the execution of a batch file, it is
  941.             useful to have the batch file stop operations while you do
  942.             something, like load paper into the printer.  The PAUSE
  943.             command halts the operation of a batch file temporarily.
  944.             
  945.             Like many other batch file commands, PAUSE allows you to
  946.             include a message.  As an example, you can create a batch
  947.             file which tells the user to put a blank, formatted disk in
  948.             drive B: before a COPY operation.  Here is the command to
  949.             use:
  950.             
  951.             PAUSE Place a blank, formatted disk in drive B:
  952.             
  953.             When DOS encounters this line in a batch file, it displays
  954.             the following information on the screen:
  955.             
  956.             Place a blank, formatted disk in drive B:
  957.             Strike a key when ready...
  958.             
  959.             The batch file stops until the user presses any key.  When a
  960.             key is pressed, the batch file moves to the next line and
  961.             executes the command there.  The command might be to COPY a
  962.             file or files to the disk the user inserted in drive B:, as
  963.             requested by the PAUSE message.
  964.             
  965.             The PROMPT Command
  966.             
  967.             In the previous part of this series, you learned to use the
  968.             PROMPT command to replace the standard DOS system prompt
  969.             with a message.  This command can also be use to create
  970.             other customized prompts.  Including one of these PROMPT
  971.             commands can add productivity to your work.
  972.             
  973.             This format of the PROMPT command uses the <$> character in
  974.             combination with a letter to change your normal prompt.
  975.             Here's an example:
  976.             
  977.             PROMPT $n$g
  978.             
  979.             This sets the prompt to the normal A> or C>, depending on
  980.             the default drive you've set.  If you'd rather see a prompt
  981.             which displays the current directory, include this variation
  982.             in your AUTOEXEC.BAT file:
  983.             
  984.             PROMPT $p$g
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.                                              Page 16
  995.  
  996.  
  997.             
  998.             There are a number of other characters, which set the
  999.             prompt.  You can use them in any combination you choose,
  1000.             preceding each letter with a dollar sign.
  1001.             
  1002.             Character                  Display
  1003.             
  1004.             $t              The current time
  1005.             $d              The current date
  1006.             $p              The current directory
  1007.             $v              The DOS version number
  1008.             $n              The current drive
  1009.             $g              The ">" character
  1010.             $l              The "<" character
  1011.             $b              The "|" character
  1012.             $_ (underscore) A carriage return
  1013.             
  1014.             Using a combination of these character commands, along with
  1015.             text, you can create customized prompts.  Just for an
  1016.             example, let's look at a complex PROMPT command:
  1017.             
  1018.             PROMPT Hello, Mary$_It's $t$_You're in the $p
  1019.             directory$_Please enter a DOS command $g
  1020.             
  1021.             PROMPT commands must be entered on a single line, so don't
  1022.             include any carriage returns.  When this PROMPT is included
  1023.             in a batch file it will produce a prompt which looks like
  1024.             this on the monitor:
  1025.             
  1026.             Hello, Mary
  1027.             It's 9:25:32.21 (current time)
  1028.             You're in the \UTILITY directory (actual directory)
  1029.             Please enter a DOS command >
  1030.             
  1031.             Experiment with this command to create custom prompts for
  1032.             yourself, or to provide information to other PC users.
  1033.             Including a special PROMPT command in your batch files can
  1034.             increase your productivity and prevent confusion.
  1035.             
  1036.             The REM Command
  1037.             
  1038.             Working with batch files is actually a form of programming.
  1039.             As your batch files grow in length, they can become
  1040.             confusing.  Inserting comments can help you understand how
  1041.             the file works.  This is especially important when you need
  1042.             to change a complex batch file later.
  1043.             
  1044.             The REM command allows you to insert comments in your files.
  1045.             Any text in a batch file which follows a REM command can
  1046.             contain your comments.  These comments will not be seen on
  1047.             the monitor, but will appear when you TYPE the file or print
  1048.             it out.  I recommend using REM comments frequently in long
  1049.             and complex batch files you create.
  1050.             
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.                                              Page 17
  1061.  
  1062.  
  1063.             Here's an example:
  1064.             
  1065.             REM This batch file copies three files to Drive B:
  1066.             PAUSE Insert a blank, formatted disk in Drive B:
  1067.             COPY LETTER.DOC B:
  1068.             COPY RESUME.DOC B:
  1069.             COPY NOVEL.DOC B:
  1070.             REM The next line displays LETTER.DOC on the monitor.
  1071.             TYPE LETTER.DOC
  1072.             
  1073.             Using the DOS Redirection Characters
  1074.             
  1075.             Earlier in this series, the two DOS redirection characters,
  1076.             < and > were mentioned.  These characters are a powerful way
  1077.             to tell your PC to send the output of files to a different
  1078.             place than they would normally go.  Using redirection in
  1079.             your batch files can be a powerful tool.
  1080.             
  1081.             For example, you might want to print a text file from within
  1082.             a batch file.  Using the TYPE command and a redirection
  1083.             character, it's easy.  Here's a command which you can use to
  1084.             send any text file to a printer:
  1085.             
  1086.             TYPE [filename.ext] >PRN
  1087.             
  1088.             The ">" character redirects the output of the TYPE command
  1089.             from the monitor to the printer.  You will use this
  1090.             frequently.
  1091.             
  1092.             Similarly, to send a directory to the printer, include the
  1093.             following command in any batch file:
  1094.             
  1095.             DIR >PRN
  1096.             
  1097.             It's easy to see how useful this can be.  When you redirect
  1098.             the output from a command to another device, such as the
  1099.             printer, it doesn't appear in its usual place.  You can use
  1100.             the redirection character to send output to the following
  1101.             devices:
  1102.             
  1103.             PRN (a printer attached to LPT1:)
  1104.             LPT#: (A parallel port)
  1105.             COM#: (A serial port)
  1106.             CON   (The monitor)
  1107.             NUL   (Nowhere at all)
  1108.             
  1109.             The last device, NUL, is your computer's version of Never-
  1110.             Never-Land. Anything sent to the NUL device simply goes
  1111.             nowhere at all.  Oddly enough, this is very useful in batch
  1112.             files.
  1113.             
  1114.             Many DOS commands you will use in batch files produce
  1115.             messages on the screen.  The COPY command is a good example.
  1116.             Whenever you COPY a file or files, the familiar message, "#
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.                                              Page 18
  1127.  
  1128.  
  1129.             file(s) copied," appears on the screen when the operation is
  1130.             finished.
  1131.             
  1132.             There are many times when you don't want that message to
  1133.             show, especially when your batch file copies multiple files.
  1134.             Having the message appear slows down the operation, and
  1135.             clutters the screen you have so carefully created.  Here's
  1136.             an example of the use of the NUL device:
  1137.             
  1138.             COPY LETTER.DOC B: >NUL
  1139.             
  1140.             Including the redirection character and the NUL device tells
  1141.             DOS to send the message, "1 file(s) copied," to the NUL
  1142.             device instead of to the monitor.  It's very simple.
  1143.             
  1144.             Other uses for this function include getting rid of messages
  1145.             provided by many memory-resident programs.  If you don't
  1146.             want to see the message, simply redirect it to the NUL
  1147.             device in the line used to call the program.
  1148.             
  1149.             You can even use this technique to introduce delays into
  1150.             your batch files.  Simply COPY a file to the NUL device. The
  1151.             longer the file, the longer the delay.  Here's an example:
  1152.             
  1153.             COPY LETTER.DOC NUL >NUL
  1154.             
  1155.             When DOS encounters this command, it reads the file, then
  1156.             copies it right into oblivion.  The original file remains on
  1157.             the disk, but the time it takes to read the file will simply
  1158.             cause a delay in the execution of the batch file.  The
  1159.             second NUL combined with the redirection character keeps the
  1160.             COPY command message off the screen.
  1161.             
  1162.             Command Line Parameters
  1163.             
  1164.             Since a batch file can contain commands which execute other
  1165.             batch files, it is useful to be able to include variables in
  1166.             your batch files.  DOS allows you to do this with a
  1167.             parameter you include when you execute the original file.
  1168.             
  1169.             By typing the name of the batch file, a space, then the
  1170.             parameter, you can tell DOS that you have included a
  1171.             variable in your command.  You have used this feature before
  1172.             with commands like: FORMAT B: or CHKDSK A:. The drive
  1173.             designator in each of those commands is a replaceable
  1174.             parameter which you can change each time you give the
  1175.             command.
  1176.             
  1177.             These parameters, when used with batch files can represent
  1178.             anything you wish, a drive name, a file, or the command
  1179.             which starts another batch file.
  1180.             
  1181.             The replaceable parameter is represented in the batch file
  1182.             itself with a per cent sign (%), followed by a number
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.                                              Page 19
  1193.  
  1194.  
  1195.             between 1 and 9.  Whenever your file encounters this sign it
  1196.             substitutes your command line parameter for the sign.
  1197.             
  1198.             For example, to create a batch file which copies all files
  1199.             from either drive A: or drive B: to your hard disk, which is
  1200.             drive C:, using a simple command, use C.BAT below:
  1201.             
  1202.             ECHO OFF
  1203.             CLS
  1204.             COPY %1:*.* C:
  1205.             
  1206.             To use this batch file, give the following command:
  1207.             
  1208.             C A
  1209.             or
  1210.             C B
  1211.             
  1212.             With three keystrokes, you can save typing in the entire
  1213.             command sequence.  Notice that the parameter is expressed in
  1214.             the batch file with a number (%1).  You can use up to nine
  1215.             command line parameters (%1 to %9), separated by spaces in
  1216.             your batch files.  This opens up many possibilities.
  1217.             
  1218.             You can expand the C.BAT file above to accept a path
  1219.             parameter as well.  This lets you specify a directory on
  1220.             your hard disk, allowing you to copy the files to a specific
  1221.             directory.  Here's the new C.BAT:
  1222.             
  1223.             ECHO OFF
  1224.             CLS
  1225.             COPY %1:*.* C:\%2
  1226.             
  1227.             Now, give this command:
  1228.             
  1229.             C A TEMP
  1230.             
  1231.             This time, your batch file copies all files from drive A:,
  1232.             the first parameter, to the \TEMP directory on drive C:.
  1233.             Each time you execute the batch file, you can use different
  1234.             parameters to control the process.  Here's the command this
  1235.             batch file has replaced:
  1236.             
  1237.             COPY A:*.* C:\TEMP
  1238.             
  1239.             It's easy to see how many ways you can use command line
  1240.             parameters to control functions in batch files.
  1241.             
  1242.             A Batch File Telephone Dialing System
  1243.             
  1244.             Now that you've learned some of the DOS commands which are
  1245.             especially useful in batch files, it's time to use some of
  1246.             these commands for a practical application.  Since most of
  1247.             us call a small list of people regularly while we're using
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.                                              Page 20
  1259.  
  1260.  
  1261.             the computer, creating a batch file dialing system makes
  1262.             sense.
  1263.             
  1264.             This system requires a Hayes-compatible modem, and can dial
  1265.             an unlimited number of people, depending only on how many
  1266.             files you want to create.
  1267.             
  1268.             First, create a directory called \PHONE in the root
  1269.             directory of your hard disk.  Include this new directory in
  1270.             your PATH so you can access it from any other directory.  If
  1271.             you use a floppy-based PC, format a floppy disk to hold your
  1272.             dialing system.
  1273.             
  1274.             Now, using either the COPY CON command or your favorite text
  1275.             editor, create the following batch file, naming it CALL.BAT:
  1276.             
  1277.             ECHO OFF
  1278.             CLS
  1279.             CD\PHONE  REM Leave this line out for floppy systems.
  1280.             ECHO Calling %1......
  1281.             MODE COM1:1200,E,7,1 >NUL
  1282.             %1
  1283.             CD\       REM Leave this line out for floppy systems
  1284.             
  1285.             If you have a 300 or 2400 baud modem, simply substitute that
  1286.             number in the fourth line of the file.  Notice that line
  1287.             four uses the >NUL redirection routine to eliminate the
  1288.             screen message produced by the MODE command.
  1289.             
  1290.             Now, create a separate batch file for each person you want
  1291.             to include in your dialing system.  Name the files so they
  1292.             will be easy to remember, and give each file the .BAT
  1293.             extension.  For example, you might create BILL.BAT, MOM.BAT,
  1294.             DOCTOR.BAT, or any other filename you might use.  Just
  1295.             remember that the filename must be no more than eight
  1296.             characters long.
  1297.             
  1298.             Here's a sample file, named BILL.BAT
  1299.             
  1300.             ECHO OFF
  1301.             CLS
  1302.             ECHO ATDT5551234 >COM1:
  1303.             
  1304.             Naturally, you would substitute the correct phone number for
  1305.             the person you're calling.  If you are in a non-tone dialing
  1306.             area, substitute ATDP for ATDT to use pulse dialing.
  1307.             Finally, if your modem is connected to another COM port, use
  1308.             that port designator in place of COM1:.  Create as many
  1309.             files as you like, storing them all in the \PHONE directory
  1310.             or on your floppy disk.
  1311.             
  1312.             If your modem uses a different dialing command than the
  1313.             Hayes-compatible ATD? command, make another substitution in
  1314.             the ECHO line.
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.                                              Page 21
  1325.  
  1326.  
  1327.             
  1328.             Here's how the system works: To call Bill, or another person
  1329.             in your system, give the command, CALL BILL, and press
  1330.             <Enter>.  The first batch file, CALL.BAT, clears the screen,
  1331.             tells you who you are calling, then sets the communications
  1332.             parameters with the MODE command. Next, it executes the
  1333.             batch file with the name you used as a replaceable
  1334.             parameter, Bill in this case.
  1335.             
  1336.             BILL.BAT executes, using the ECHO command to send the
  1337.             dialing command and the telephone number to your modem.  At
  1338.             this point, you can listen to the progress of the call on
  1339.             your modem's speaker, or just pick up the phone and wait for
  1340.             an answer.
  1341.             
  1342.             You can use your dialing system anytime you see the system
  1343.             prompt.  Many programs allow you to exit temporarily to DOS,
  1344.             so you can also make phone calls while using any of these
  1345.             programs.
  1346.             
  1347.             You can use DOS batch files as a simple programming language
  1348.             to create programs like the dialing utility above.  The
  1349.             advantage to batch programming is its simplicity.  Creating
  1350.             a telephone dialing system in most other programming
  1351.             languages would take hours.  Using batch files, the program
  1352.             is finished in minutes.
  1353.             
  1354.             A Batch File Database
  1355.             
  1356.             Following a similar format to the telephone dialing system,
  1357.             you can create a simple database system to store names and
  1358.             addresses, using simple batch files. First, create a new
  1359.             directory called \FILE on your hard disk or format a floppy
  1360.             disk to be used for this system.  One again, if you install
  1361.             this system on your hard disk, be sure to include it in your
  1362.             PATH for easy access.
  1363.             
  1364.             Write the following batch file, LOOKUP.BAT, to serve as the
  1365.             main program:
  1366.             
  1367.             ECHO OFF
  1368.             CLS
  1369.             CD\FILE  REM You can leave this line out for floppy systems.
  1370.             ECHO Searching.......
  1371.             TYPE %1.ADD  REM This command line parameters displays the file
  1372.             CD\      REM Again, leave this line out for floppy systems.
  1373.             
  1374.             When creating this file, leave off the REM commands and the
  1375.             text following them.
  1376.             
  1377.             Now, for each person you want to include in your database,
  1378.             create a plain ASCII file which looks like this:
  1379.             
  1380.             ANYNAME DOE
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.                                              Page 22
  1391.  
  1392.  
  1393.             1235 SOME STREET
  1394.             ANYTOWN, STATE   ZIP
  1395.             (555) 555-5555
  1396.             <Enter>  REM These lines add blank lines.  Use as many
  1397.             <Enter>  REM as you need.
  1398.             
  1399.             Give the file a distinctive name you'll remember.  Use the
  1400.             extension, ADD.  Store the file in the same directory or on
  1401.             the same disk as LOOKUP.BAT.  Now, to view the information
  1402.             on your monitor, just enter the command:
  1403.             
  1404.             LOOKUP NAME
  1405.             
  1406.             Your LOOKUP.BAT file will find the filename you specify on
  1407.             the command line and display the information.  Of course,
  1408.             you might not remember just which file you want to check.
  1409.             It's easy to write another batch file which will show you a
  1410.             list of files.  You might call this one FINDFILE.BAT:
  1411.             
  1412.             ECHO OFF
  1413.             CLS
  1414.             CD\FILE  REM Not used in floppy systems.
  1415.             DIR *.ADD/W
  1416.             CD\      REM Not used in floppy systems.
  1417.             
  1418.             By entering the FINDFILE command you will see a display of
  1419.             your filenames for this system.  Notice the fourth line of
  1420.             the batch file.  It reads DIR *.ADD/W.  The *.ADD section
  1421.             tells DOS to show only those files which have the extension
  1422.             you use for your data files.  This helps keep extraneous
  1423.             information off the screen.
  1424.             
  1425.             Now, suppose you want to print one of your files.  Here's
  1426.             another batch file to do that.  Let's call this one
  1427.             PRINTIT.BAT.
  1428.             
  1429.             ECHO OFF
  1430.             CLS
  1431.             CD\FILE  REM Not used in floppy systems.
  1432.             COPY %1.ADD PRN
  1433.             CD\      REM Not used in floppy systems.
  1434.             
  1435.             All you have to do is enter a command like this one:
  1436.             
  1437.             PRINTIT NAME
  1438.             
  1439.             The file you name on the command line will go directly to
  1440.             your printer.  If you have included the right number of
  1441.             blank lines in your original files, you can use this
  1442.             PRINTIT.BAT to print address labels.  You'll have to
  1443.             experiment to get your files just right for your particular
  1444.             printer and labels.
  1445.             
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.                                              Page 23
  1457.  
  1458.  
  1459.             Finally, you can write one more batch file which will print
  1460.             your entire list of files, creating mailing labels if you
  1461.             have formatted the files properly.  Call this one
  1462.             PRINTALL.BAT.
  1463.             
  1464.             ECHO OFF
  1465.             CLS
  1466.             CD\FILE  REM Not used in floppy systems.
  1467.             COPY *.ADD PRN >NUL
  1468.             CD\      REM Not used in floppy systems.
  1469.             
  1470.             Enter the command, PRINTALL, and every one of your files
  1471.             will be printed automatically.
  1472.             
  1473.             This address system is only one way you can use your batch
  1474.             file database.  Another possibility is a recipe database.
  1475.             By storing files containing your recipes, you can use the
  1476.             same batch files to call up your favorites, print them out,
  1477.             or even print the entire recipe database.
  1478.             
  1479.             Just remember that any files you store in your batch file
  1480.             database must be pure ASCII files, created with either the
  1481.             COPY CON command or your favorite word processor or text
  1482.             editor.  If you use a word processor, be sure to save the
  1483.             files in ASCII format.
  1484.             
  1485.             The possibilities for different kinds of data storage are
  1486.             endless. You also have the advantage of not being restricted
  1487.             to defined fields and field sizes, as you do with a regular
  1488.             database.
  1489.             
  1490.             In the next part of this series, you will learn several
  1491.             advanced batch file techniques, including ways you can use
  1492.             batch files in your programming.  That part will also cover
  1493.             the creation of a batch file system to control your printer.
  1494.             It will allow you to change your printer's output with a
  1495.             single command.
  1496.             
  1497.             
  1498.             
  1499.             
  1500.                        Part 4: Advanced Batch File Techniques
  1501.             
  1502.             
  1503.             The first two parts of this series on batch files introduced
  1504.             a number of techniques to help you automate many of the
  1505.             operations you perform frequently on your PC.  This time,
  1506.             we're going to take a look at more advanced batch file
  1507.             functions, adding even more power to your batch processing.
  1508.             
  1509.             Like all programming languages, batch files can perform
  1510.             loops and conditional branching.  Loops allow your batch
  1511.             program to perform the same function several times, using
  1512.             information you supply to control the process.  Conditional
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.                                              Page 24
  1523.  
  1524.  
  1525.             branching lets your batch files test to see if a condition
  1526.             is true and, if it is, forces the batch file to execute a
  1527.             subroutine.  Let's look at conditional branching first.
  1528.             
  1529.             BATCH FILE IF....GOTO BRANCHING
  1530.             
  1531.             If you are familiar with any programming languages, such as
  1532.             BASIC, the IF....GOTO sequence is familiar to you.  The IF
  1533.             part of the sequence lets you test something, while the GOTO
  1534.             command tells your program to skip to a subroutine and carry
  1535.             out the commands it finds there.  This capability is central
  1536.             to all programming, including batch programming.
  1537.             
  1538.             Before looking at the IF command, it's important to
  1539.             understand how the GOTO command works.  Unlike many
  1540.             languages, DOS batch programs use labels with the GOTO
  1541.             command. A label marks the beginning of the subroutine,
  1542.             letting DOS know where to begin processing after it
  1543.             encounters a GOTO line.
  1544.             
  1545.             Batch file labels always begin with a colon (:).  The label
  1546.             follows the colon, without any spaces or other characters.
  1547.             Here are some examples of correct label format:
  1548.             
  1549.                       :START
  1550.                       :ABORT
  1551.                       :QUIT
  1552.             
  1553.             
  1554.             A label should be placed on a line by itself, immediately
  1555.             preceding the first command in the subroutine.  This sample
  1556.             batch file, called SAMPLE.BAT, will demonstrate the use of
  1557.             the GOTO command:
  1558.             
  1559.                       ECHO OFF
  1560.                       CLS
  1561.                       ECHO This batch file demonstrates branching.
  1562.                       GOTO ROUTINE1
  1563.                       ECHO The batch file will skip this line.
  1564.                       ECHO It will skip this line as well.
  1565.                       :ROUTINE1
  1566.                       CLS
  1567.                       ECHO You are now in the first sub-routine.
  1568.                       ECHO When you press a key, you will go to the next
  1569.                       routine.
  1570.                       PAUSE
  1571.                       GOTO ROUTINE2
  1572.                       ECHO Again, the batch file will skip this line.
  1573.                       ECHO And this one, too.
  1574.                       :ROUTINE2
  1575.                       CLS
  1576.                       ECHO Now you are in the second sub-routine.
  1577.                       ECHO Notice that the file skipped several lines.
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.                                              Page 25
  1589.  
  1590.  
  1591.                       ECHO Pressing a key will take you to the third
  1592.                       routine.
  1593.                       PAUSE
  1594.                       GOTO ROUTINE3
  1595.                       ECHO Another line skipped.
  1596.                       ECHO Still another skipped line.
  1597.                       :ROUTINE3
  1598.                       CLS
  1599.                       ECHO Now you have reached the third subroutine.
  1600.                       ECHO This is the last subroutine.
  1601.                       ECHO When you press a key, you will exit to DOS.
  1602.                       PAUSE
  1603.                       CLS
  1604.             
  1605.             Create this simple batch file, using the COPY CON command or
  1606.             your favorite text editor.  Remember to save the file in
  1607.             ASCII format.  Once you have created the file, run it.  You
  1608.             will notice that the lines between the GOTO commands and the
  1609.             labels do not execute.  Once DOS encounters the GOTO, it
  1610.             immediately jumps to the label, skipping all intermediate
  1611.             lines.
  1612.             
  1613.             When creating a label, use from one to eight characters.
  1614.             Avoid punctuation, and always use labels which are
  1615.             meaningful, to help you understand your batch file later.
  1616.             Unlike other languages, DOS allows you to use reserved
  1617.             words, like COPY and DELETE as labels in your batch files.
  1618.             For clarity's sake, however, it's best to avoid labels which
  1619.             are also the names of DOS commands.
  1620.             
  1621.             CONDITIONAL BRANCHING WITH THE IF COMMAND
  1622.             
  1623.             By itself, the GOTO command has limited usefulness. There is
  1624.             usually no reason to use GOTO unless you are testing to see
  1625.             if a condition is true or not.  That's where the IF command
  1626.             comes in.
  1627.             
  1628.             Most programming languages use a command similar to the DOS
  1629.             IF command to test for a wide variety of conditions.  In
  1630.             batch files, you are limited to testing just a few things:
  1631.             
  1632.             1. Whether one string of characters equals another.
  1633.             2. Whether or not a file exists.
  1634.             3. The ERRORLEVEL of a program.
  1635.             
  1636.             In this article, we'll look at the first two conditions.
  1637.             The third is of limited usefulness to most DOS users.
  1638.             
  1639.             The first condition which can be tested with the IF command,
  1640.             whether one string is equal to another, is the most common.
  1641.             If you remember the discussion on command-line parameters,
  1642.             you know that a batch file can use up to 10 parameters when
  1643.             you give the command to execute the batch file.  An example
  1644.             of this might be the command, FORMAT A:.  The A: part of
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.                                              Page 26
  1655.  
  1656.  
  1657.             this command is a replaceable parameter, used by DOS to
  1658.             identify the drive to be formatted.
  1659.             
  1660.             By using the IF command in your batch files, you can check
  1661.             to see whether a command-line parameter equals a string you
  1662.             have specified in the batch file.  Here's an example, which
  1663.             we'll call TEST1.BAT:
  1664.             
  1665.             
  1666.                  ECHO OFF
  1667.                  CLS
  1668.                  IF %1. == . GOTO WRONG
  1669.                  IF %1 == HELLO GOTO CORRECT
  1670.                  GOTO END
  1671.                  :CORRECT
  1672.                  CLS
  1673.                  ECHO You typed HELLO.
  1674.                  ECHO The batch file branched to the CORRECT routine.
  1675.                  PAUSE
  1676.                  GOTO END
  1677.                  :WRONG
  1678.                  CLS
  1679.                  ECHO You didn't include a parameter in your command.
  1680.                  ECHO To get to the subroutine, type the command:
  1681.                  ECHO TEST1 HELLO, then press [Enter].
  1682.                  PAUSE
  1683.                  GOTO END
  1684.                  :END
  1685.                  ECHO You typed something other than HELLO as a
  1686.                  parameter.
  1687.                  ECHO DOS recognizes the difference between upper and
  1688.                  lower case.
  1689.                  ECHO Try again.
  1690.                  PAUSE
  1691.                  CLS
  1692.             
  1693.             Let's take a look at some of the lines in this file.  The
  1694.             first two lines are familiar, turning off ECHO and clearing
  1695.             the screen.  The next line is new and uses the IF command.
  1696.             
  1697.             When you use the IF command to check command-line parameters
  1698.             and no parameter is given when the batch file is called, DOS
  1699.             normally returns the error message: SYNTAX ERROR.  The line
  1700.             in TEST1.BAT which reads: IF %1. == . GOTO WRONG GOTO END
  1701.             tests to see if no parameter was given.  The period (.) is
  1702.             used to supply a single character following the %1
  1703.             parameter.  Without it, the error message INVALID NUMBER OF
  1704.             PARAMETERS would appear.  This line branches to the :WRONG
  1705.             subroutine if no parameter was used on the command line.
  1706.             
  1707.             The next line checks to see if the command-line parameter
  1708.             was HELLO.  If it was, the batch file branches to the
  1709.             routine named :CORRECT.
  1710.             
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.                                              Page 27
  1721.  
  1722.  
  1723.             Following the second IF line is a line which reads, GOTO
  1724.             END.  This line comes into play if neither of the conditions
  1725.             in the previous lines is true.  If, for example, the
  1726.             command-line parameter was GOODBYE, the batch file would
  1727.             branch to the :END routine, skipping the rest of the file.
  1728.             
  1729.             It's important to include a line which branches around other
  1730.             lines if a condition isn't true.  Otherwise, the batch file
  1731.             would simply go right into the :CORRECT subroutine.
  1732.             
  1733.             The IF command recognizes upper and lower case letters as
  1734.             different.  So, typing hello in lower case letters would not
  1735.             satisfy the condition in the second IF line.
  1736.             
  1737.             Finally, notice that each subroutine in this batch file
  1738.             includes a GOTO END line.  Again, this forces the program to
  1739.             branch around succeeding subroutines, avoiding errors.
  1740.             
  1741.             Create this batch file, then run it.  The first time, do not
  1742.             include the parameter HELLO on the command line.  Next, add
  1743.             hello to the command, using lower-case letters.  Finally,
  1744.             include the correct form of the parameter, HELLO.  You will
  1745.             see the messages in the appropriate subroutine.  Be sure to
  1746.             use two equal signs (==) in your IF lines.  This is
  1747.             critical.
  1748.             
  1749.             Creating a Practical Application Using Branching
  1750.             
  1751.             While the sample batch file above demonstrates the use of
  1752.             the IF and GOTO commands, it doesn't serve any useful
  1753.             function.  Let's create a batch file which solves a serious
  1754.             problem.
  1755.             
  1756.             It's all too easy to accidentally format a hard disk,
  1757.             particularly with versions of DOS earlier than 3.0. By
  1758.             simply typing the command FORMAT and pressing a key, all
  1759.             your hard disk files can be destroyed.  DOS 3.0 and later
  1760.             add a warning message, but an unwary user or a malicious
  1761.             intruder can still easily format any hard disk.
  1762.             
  1763.             You can protect yourself against this disaster with the
  1764.             following batch file.  It's called FORMAT.BAT.  Since PC/MS-
  1765.             DOS will execute a .COM file before a .BAT file, you need to
  1766.             rename the DOS formatting utility.
  1767.             
  1768.             Change to your DOS directory, and give the following
  1769.             command:
  1770.             
  1771.             REN FORMAT.COM FRMT.COM
  1772.             
  1773.             This is the first step in your protection scheme.  Renaming
  1774.             the FORMAT.COM allows your FORMAT.BAT file to take over when
  1775.             the command, FORMAT, is given.
  1776.             
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.                                              Page 28
  1787.  
  1788.  
  1789.             Now, create the following batch file, storing it in a
  1790.             directory on your hard disk which is included in your path
  1791.             statement.  Do not include the REM statement explaining how
  1792.             to enter the Ctrl+G command.  Name the file FORMAT.BAT.
  1793.             
  1794.             
  1795.                  ECHO OFF
  1796.                  CLS
  1797.                  IF %1. == . GOTO NOPARM
  1798.                  IF %1 == A: GOTO CORRECT
  1799.                  IF %1 == a: GOTO CORRECT
  1800.                  IF %1 == B: GOTO CORRECT
  1801.                  IF %1 == b: GOTO CORRECT
  1802.                  IF %1 == C: GOTO ABORT
  1803.                  IF %1 == c: GOTO ABORT
  1804.                  IF %1 == D: GOTO ABORT
  1805.                  IF %1 == d: GOTO ABORT
  1806.                  GOTO WRONG
  1807.                  :NOPARM
  1808.                  ECHO ^G   REM ***Hold down Ctrl and press the G key***
  1809.                  ECHO You must enter a drive designator to format a
  1810.                  disk.
  1811.                  ECHO Enter the command this way...FORMAT A:... using
  1812.                  the
  1813.                  ECHO drive designator for the correct drive.
  1814.                  PAUSE
  1815.                  GOTO END
  1816.                  :CORRECT
  1817.                  ECHO Preparing to format a floppy disk.
  1818.                  PAUSE
  1819.                  FRMT %1
  1820.                  GOTO END
  1821.                  :ABORT
  1822.                  ECHO ^G
  1823.                  ECHO ^G
  1824.                  ECHO You have specified a hard disk for formatting!
  1825.                  ECHO You cannot format your hard disk from this batch
  1826.                  file!
  1827.                  ECHO Use an alternate method!
  1828.                  PAUSE
  1829.                  GOTO END
  1830.                  :WRONG
  1831.                  ECHO ^G
  1832.                  ECHO You have entered an invalid drive designator...
  1833.                  ECHO Try again.  Don't forget the colon. (:)
  1834.                  GOTO END
  1835.                  :END
  1836.                  CLS
  1837.             
  1838.             Let's take a look at the IF statements in this file.  First,
  1839.             using the technique discussed earlier, the file checks to
  1840.             see if a parameter has been included in the command line.
  1841.             If not, it branches to a subroutine called :NOPARM, which
  1842.             tells the user to include a drive designator.
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.                                              Page 29
  1853.  
  1854.  
  1855.             
  1856.             Next, the batch file checks to see if the parameter entered
  1857.             on the command line is a floppy drive.  It tests for upper
  1858.             and lower case entries for drives A: and B:.  If any floppy
  1859.             disk drive designator is given, the file branches to the
  1860.             :CORRECT subroutine.  There, the FRMT command is given,
  1861.             executing the renamed formatting utility.  The original
  1862.             command line parameter %1 passes to the FRMT.COM program.
  1863.             
  1864.             The next four lines check to see if the user entered the
  1865.             name of a hard disk, either drive C: or drive D:.  Again,
  1866.             both upper and lower case are tested.  If these drives are
  1867.             on the command line, the batch file branches to the :ABORT
  1868.             subroutine.  That routine sounds an alarm and refuses to
  1869.             format the hard disk.
  1870.             
  1871.             Finally, if the user has specified an invalid drive, or left
  1872.             off the colon (:) following the drive letter, the GOTO WRONG
  1873.             line sends the program to another routine, which explains
  1874.             the error.
  1875.             
  1876.             Notice that each routine ends with a GOTO END line.  This is
  1877.             very important, and keeps the batch file from accidentally
  1878.             drifting into another routine.
  1879.             
  1880.             You can customize this hard disk protection system to fit
  1881.             your particular configuration.  Just alter it to reflect the
  1882.             drives on your own PC.
  1883.             
  1884.             You should be able to think of a number of other ways to use
  1885.             this feature of the IF command.  Branching is an excellent
  1886.             way to add power to your batch files.
  1887.             
  1888.             TESTING FOR THE EXISTENCE OF A FILE
  1889.             
  1890.             The IF command can also check whether or not a particular
  1891.             file exists.  This can be very useful.  For example, if you
  1892.             wanted to copy files from a floppy disk onto your hard disk,
  1893.             but only if that file already exists on the hard disk, this
  1894.             use of the IF command can save you time.  You might do this
  1895.             to update files on the hard disk.
  1896.             
  1897.             Here is a batch file which does just that.  Call it
  1898.             COPYIF.BAT.
  1899.             
  1900.                  ECHO OFF
  1901.                  CLS
  1902.                  IF EXIST C:\%1\%2 GOTO EXECUTE
  1903.                  GOTO WRONG
  1904.                  :EXECUTE
  1905.                  ECHO Copying A:%2 to C:\%1 directory...
  1906.                  COPY A:%2 C:\%1
  1907.                  PAUSE
  1908.                  GOTO END
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.                                              Page 30
  1919.  
  1920.  
  1921.                  :WRONG
  1922.                  ECHO That file does not exist in the C:\%1 directory.
  1923.                  PAUSE
  1924.                  GOTO END
  1925.                  :END
  1926.                  CLS
  1927.             
  1928.             After creating COPYIF.BAT, try it out.  Put a floppy disk in
  1929.             drive A: which contains files which are also in a directory
  1930.             on your hard disk.
  1931.             
  1932.             Use the DIR command to get a list of files.  Now type the
  1933.             following command:
  1934.             
  1935.             COPYIF [DIRECTORY NAME] [FILENAME]
  1936.             
  1937.             Substitute appropriate information in the command to fit
  1938.             your particular directory and files. When the batch file
  1939.             runs, it will check the directory (%1) for the file (%2),
  1940.             then copy the file from drive A: if it finds the file also
  1941.             in the directory on drive C:
  1942.             
  1943.             Try this again, but name a directory which doesn't contain
  1944.             the file you name on the command line.  You can see how the
  1945.             IF command works here.
  1946.             
  1947.             This is a useful batch file, but it might even be more
  1948.             useful if it only copied the file from drive A: into the
  1949.             directory if that file did NOT already exist in the
  1950.             directory you name.
  1951.             
  1952.             DOS can do this as well.  To change COPYIF.BAT to perform
  1953.             this function, just change the third line to read:
  1954.             
  1955.                  IF NOT EXIST C:\%1\%2 GOTO EXECUTE
  1956.             
  1957.             Make this change in your COPYIF.BAT file, and save it with
  1958.             the new name COPYNOT.BAT.  Try this new batch file the same
  1959.             way you did before. Now it only copies the file from drive
  1960.             A: if it doesn't exist on drive C: in the specified
  1961.             directory.  A batch file like COPYNOT.BAT is one way to
  1962.             prevent overwriting an existing file.
  1963.             
  1964.             
  1965.             BATCH FILE LOOPS WITH FOR...IN...DO
  1966.             
  1967.             No programming language is complete without a way of
  1968.             creating loops.  A loop is a way of repeating a routine as
  1969.             long as a certain condition exists.  DOS allows a limited
  1970.             use of loops in batch files, using the FOR...IN...DO command
  1971.             series.
  1972.             
  1973.             These loops are limited to dealing with filenames as the
  1974.             limiting structures. Here is the syntax:
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.                                              Page 31
  1985.  
  1986.  
  1987.             
  1988.             FOR %%variable IN (set) DO command
  1989.             
  1990.             That's slightly confusing.  The %%variable is a dummy
  1991.             variable, composed of a single character.  An example is
  1992.             %%A.  All this really does is give DOS a handle to work
  1993.             with.
  1994.             
  1995.             The (set) described in the syntax is a list of files.  Most
  1996.             often, this set uses DOS wildcards (? & *) to represent
  1997.             groups of files.  For example, typical sets might include
  1998.             (*.*), (C:\*.*) or (C:\WP\DOC\*.BAK). You can include
  1999.             multiple entries inside the parentheses.  To act on all
  2000.             .DOC,.BAK, and .TXT files, the set would be
  2001.             (*.DOC,*.BAK,*.TXT). You can use either commas or spaces to
  2002.             separate the individual files or wildcard entries.  Just
  2003.             remember that the set you specify is the group of files you
  2004.             want to act upon.
  2005.             
  2006.             Finally, the command part of this structure can be any DOS
  2007.             command.  To make this complex command series clearer, let's
  2008.             create a sample batch file.  What this file will do is
  2009.             delete all the files with the extension .BAK in the \WP\DOC
  2010.             subdirectory on drive C:  This is something most users do
  2011.             from time to time.  Naturally, you can substitute any other
  2012.             directory when you create the file.  Call the file
  2013.             KILLBAK.BAT.
  2014.             
  2015.             
  2016.                  ECHO OFF
  2017.                  CLS
  2018.                  ECHO This file will delete all .BAK files from
  2019.                  C:\WP\DOC.
  2020.                  ECHO If you do not want to do this, press
  2021.                  [Ctrl]+[Break].
  2022.                  PAUSE
  2023.                  FOR %%A IN (C:\WP\DOC\*.BAK) DO DEL %%A
  2024.                  ECHO All files with the extension .BAK have been
  2025.                  deleted.
  2026.                  PAUSE
  2027.                  CLS
  2028.             
  2029.             You can use any DOS command in place of DEL.  If, for
  2030.             example, you wanted to copy all files with the extension
  2031.             .COM from drive A: to drive B:, the command would look like
  2032.             this:
  2033.             
  2034.             FOR %%A IN (*.COM) DO COPY A:%%A B:
  2035.             
  2036.             Similarly, to print out all your .BAT files in the \BATCH
  2037.             directory on your hard disk, the command would look like
  2038.             this:
  2039.             
  2040.             FOR %%A IN (*.BAT) DO COPY C:\BATCH\%%A PRN
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.                                              Page 32
  2051.  
  2052.  
  2053.             
  2054.             It's easy to see how useful this looping command structure
  2055.             can be in your batch files.  You can repeatedly perform a
  2056.             DOS command, controlling the files it operates on by
  2057.             changing the variables in the FOR...IN...DO command
  2058.             structure.  Experiment with these commands in your batch
  2059.             files.
  2060.             
  2061.             CONTROLLING YOUR PRINTER WITH BATCH FILES
  2062.             
  2063.             In the last part of this series of articles, I promised that
  2064.             I would include a method of controlling your printer using
  2065.             batch files.  While the current crop of dot-matrix printers
  2066.             have some wonderful capabilities, making use of them can be
  2067.             a chore.
  2068.             
  2069.             You can either write a short program in BASIC to send
  2070.             commands to the printer, or use a special printer utility
  2071.             program.  Both of these systems work, but take time you
  2072.             could spend more productively.
  2073.             
  2074.             The problem lies in DOS.  In its wisdom, Microsoft wrote
  2075.             PC/MS-DOS in a way that prevents you from sending the Escape
  2076.             character (ASCII 27) to your printer.  You can send almost
  2077.             any other character to the printer in a batch file with the
  2078.             ECHO command and the redirection character (>).  Any other
  2079.             character, that is, except the Escape character.
  2080.             
  2081.             Most printer commands are preceded with the Escape
  2082.             character, so it's normally impossible to control your
  2083.             printer from the system prompt.
  2084.             
  2085.             For this printer control system to work, then, you need a
  2086.             program which can do what DOS can't do.  Fortunately for all
  2087.             of us, Calvin R. Shields has placed such a program in the
  2088.             public domain.  A short program, written in assembly
  2089.             language, it also illustrates another use of batch files.
  2090.             
  2091.             Create the following batch file, using your favorite method.
  2092.             Be very careful to type the program exactly as it appears
  2093.             here, including the blank lines.  Call it MAKE-ESC.BAT.
  2094.             
  2095.                       GOTO START
  2096.                       A  100
  2097.                       XOR     DX,DX
  2098.                       MOV     AX,001B
  2099.                       INT     17
  2100.                       MOV     BX,0080
  2101.                       MOV     CL,[BX]
  2102.                       XOR     CH,CH
  2103.                       JCXZ    011F
  2104.                       INC     BX
  2105.                       DEC     CX
  2106.                       JCXZ    011F
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.                                              Page 33
  2117.  
  2118.  
  2119.                       INC     BX
  2120.                       MOV     AL,[BX]
  2121.                       XOR     DX,DX
  2122.                       XOR     AH,AH
  2123.                       INT     17
  2124.                       LOOP    0114
  2125.                       INT     20
  2126.                       
  2127.                       R  CX
  2128.                       21
  2129.                       n  esc.com
  2130.                       w
  2131.                       q
  2132.                       
  2133.                       :START
  2134.                       DEBUG < MAKE-ESC.BAT
  2135.             
  2136.             
  2137.             Notice the first line of the file, which sends the program
  2138.             to the :START subroutine.  There, this batch file calls the
  2139.             DOS DEBUG program, using the redirection character to make
  2140.             DEBUG assemble the program, ESC.COM, from the assembly
  2141.             language routines included in the batch file.  This is a
  2142.             very creative use of batch files.
  2143.             
  2144.             Before running this batch file, make sure that DEBUG.COM or
  2145.             DEBUG.EXE (depending on your version of DOS) is in your
  2146.             current path.  If you are using floppy disks, copy the DEBUG
  2147.             program onto the disk containing MAKE-ESC.BAT.
  2148.             
  2149.             Run the batch file.  You will see a brief error message,
  2150.             caused when DEBUG finds the first line of the program.
  2151.             Ignore this message.  Once the file runs, you will have a
  2152.             33-byte program called ESC.COM on your disk.  This program
  2153.             does what DOS can't do:  it sends the Escape character to
  2154.             your printer, which must be connected to the parallel port,
  2155.             LPT1:.
  2156.             
  2157.             To make ESC.COM work, all you have to do is give the
  2158.             command, ESC, followed by a space and the command you want
  2159.             to send to the printer.  For example, the command which
  2160.             resets an Epson-compatible printer looks like this:
  2161.             
  2162.                       ESC @  <Enter>
  2163.                       
  2164.             The simplicity of these commands makes controlling your
  2165.             printer easy.  But who can remember all the commands?
  2166.             That's where batch files come into the picture.
  2167.             
  2168.             To create a system for setting your printer's
  2169.             characteristics, all you have to do is write a short batch
  2170.             file which gives the commands needed to set the printer.
  2171.             Name each batch file with an easy-to-remember name.
  2172.             
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.                                              Page 34
  2183.  
  2184.  
  2185.             The batch files which follow will work with any Epson or
  2186.             Epson-compatible printer.  If you use another type of
  2187.             printer, substitute the command for your printer in the
  2188.             batch file.
  2189.             
  2190.             Let's start with the reset command, which will put the
  2191.             printer in the start-up mode.  Call this file RESET.BAT.
  2192.             
  2193.                       ECHO OFF
  2194.                       CLS
  2195.                       ESC @
  2196.             
  2197.             Here's another file. This one sets the printer to its Near
  2198.             Letter Quality mode.  Call it NLQ.BAT.
  2199.             
  2200.                       ECHO OFF
  2201.                       CLS
  2202.                       ESC X1
  2203.             
  2204.             I've included the ECHO OFF and CLS lines to keep your screen
  2205.             clear when you issue the commands.
  2206.             
  2207.             Here's another sample.  Call this one BOLD.BAT.
  2208.             
  2209.                       ECHO OFF
  2210.                       CLS
  2211.                       ESC E
  2212.             
  2213.             By consulting your printer's manual, you can find all the
  2214.             commands which make your printer jump through its hoops.
  2215.             Write a separate batch file for each command, and you will
  2216.             soon have a printer control system which can handle every
  2217.             function.  You can also combine functions by entering the
  2218.             commands, one-at-a-time.
  2219.             
  2220.             If your printer is an Epson compatible, the batch files in
  2221.             LISTING 1 will handle almost every possible function.
  2222.             Again, if you use another kind of printer, consult your
  2223.             manual for the appropriate commands.
  2224.             
  2225.             Place the batch files and the ESC.COM program in a directory
  2226.             which is in your current path.  Then, whenever you need to
  2227.             send a command to your printer, just give the name of the
  2228.             appropriate batch file as a DOS command.
  2229.             
  2230.             The next part of this series will show you how to make batch
  2231.             files even more flexible, using additional commands and
  2232.             external programs.  There are a number of commercial, public
  2233.             domain, and shareware programs which can add power to your
  2234.             batch programming.
  2235.             
  2236.                                  ##End main copy##
  2237.             
  2238.             
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.                                              Page 35
  2249.  
  2250.  
  2251.             
  2252.             
  2253.                                      LISTING 1
  2254.             
  2255.             These batch files are designed to be used with the ESC.COM
  2256.             program in the main article.  If your printer is Epson-
  2257.             compatible, the system will work as written.  If you have
  2258.             another brand of printer, substitute the appropriate
  2259.             commands.  Create these files using the COPY CON command or
  2260.             use your favorite text editor in its ASCII Mode.
  2261.             
  2262.             
  2263.             RESET.BAT -- Sets the printer to its default mode.
  2264.             
  2265.                  ECHO OFF
  2266.                  CLS
  2267.                  ESC @
  2268.             
  2269.             
  2270.             PICA.BAT -- Sets pica (10 characters/in.)
  2271.             
  2272.                  ECHO OFF
  2273.                  CLS
  2274.                  ESC P
  2275.             
  2276.             
  2277.             ELITE.BAT -- Sets elite (12 characters/in.)
  2278.             
  2279.                  ECHO OFF
  2280.                  CLS
  2281.                  ESC M
  2282.             
  2283.             
  2284.             CONDENSE.BAT -- Sets condensed type.
  2285.             
  2286.                  ECHO OFF
  2287.                  CLS
  2288.                  ESC ^O  REM **<CTRL>+<O>**
  2289.             
  2290.             
  2291.             TINY.BAT -- Sets microtype (20+ characters/in.)
  2292.             
  2293.                  ECHO OFF
  2294.                  CLS
  2295.                  ESC M
  2296.                  ESC ^O  REM **<CTRL>+<O>**
  2297.                  ESC S1
  2298.                  ESC 1
  2299.             
  2300.             
  2301.             ITALIC.BAT -- Sets italic mode
  2302.             
  2303.                  ECHO OFF
  2304.                  CLS
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.                                              Page 36
  2315.  
  2316.  
  2317.                  ESC 4
  2318.                  
  2319.             
  2320.             UNITALIC.BAT -- Cancels italic mode
  2321.             
  2322.                  ECHO OFF
  2323.                  CLS
  2324.                  ESC 5
  2325.             
  2326.             
  2327.             
  2328.             WIDE.BAT -- Sets double-width type
  2329.             
  2330.                  ECHO OFF
  2331.                  CLS
  2332.                  ESC W1
  2333.             
  2334.             
  2335.             UNWIDE.BAT -- Cancels double-width
  2336.             
  2337.                  ECHO OFF
  2338.                  CLS
  2339.                  ESC W0
  2340.             
  2341.             
  2342.             NLQ.BAT -- Sets Near Letter Quality mode.
  2343.             
  2344.                  ECHO OFF
  2345.                  CLS
  2346.                  ESC x1
  2347.             
  2348.             
  2349.             UNLQ.BAT -- Cancels Near Letter Quality
  2350.             
  2351.                  ECHO OFF
  2352.                  CLS
  2353.                  ESC x0
  2354.             
  2355.             
  2356.             6LPI.BAT -- Sets 6 line/in. spacing.
  2357.             
  2358.                  ECHO OFF
  2359.                  CLS
  2360.                  ESC 2
  2361.             
  2362.             
  2363.             8LPI.BAT -- Sets 8 line/in. spacing.
  2364.             
  2365.                  ECHO OFF
  2366.                  CLS
  2367.                  ESC 0
  2368.             
  2369.             
  2370.             10LPI.BAT -- Sets 10 line/in. spacing.
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.                                              Page 37
  2381.  
  2382.  
  2383.             
  2384.                  ECHO OFF
  2385.                  CLS
  2386.                  ESC 1
  2387.             
  2388.             
  2389.             BOLD.BAT -- Sets Boldface.
  2390.             
  2391.                  ECHO OFF
  2392.                  CLS
  2393.                  ESC E
  2394.             
  2395.             
  2396.             NOBOLD.BAT -- Cancels Boldface.
  2397.             
  2398.                  ECHO OFF
  2399.                  CLS
  2400.                  ESC F
  2401.             
  2402.             
  2403.             UNDRLINE.BAT -- Underlines all text.
  2404.             
  2405.                  ECHO OFF
  2406.                  CLS
  2407.                  ESC -1
  2408.             
  2409.             
  2410.             NO-UNDER.BAT -- Cancels underlining.
  2411.             
  2412.                  ECHO OFF
  2413.                  CLS
  2414.                  ESC -0
  2415.             
  2416.             
  2417.             2STRIKE.BAT -- Starts double-strike mode.
  2418.             
  2419.                  ECHO OFF
  2420.                  CLS
  2421.                  ESC G
  2422.             
  2423.             
  2424.             1STRIKE.BAT -- Starts single-strike mode.
  2425.             
  2426.                  ECHO OFF
  2427.                  CLS
  2428.                  ESC H
  2429.             
  2430.                                  ##End Listing 1##
  2431.             
  2432.             
  2433.             
  2434.             
  2435.             
  2436.             
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.             Campbell -- Batch Power          Page 38
  2447.  
  2448.  
  2449.             
  2450.             
  2451.             
  2452.             
  2453.                          The Power of PC\MS-DOS Batch Files
  2454.                                           
  2455.                                          by
  2456.                                   George Campbell
  2457.                                           
  2458.                                           
  2459.                              Part 4: Adding More Power
  2460.             
  2461.             
  2462.             
  2463.             In the first three parts of this series on batch files, you
  2464.             learned many of the techniques possible with PC/MSDOS batch
  2465.             processing. By now, you're probably using batch files to
  2466.             perform many functions you used to do, one command at a
  2467.             time, from the system prompt.
  2468.             
  2469.             In this article, which will be the last part of this series,
  2470.             you'll learn ways you can expand your batch processing even
  2471.             further.  Although PC/MSDOS batch files have the power to
  2472.             make your PC do things you didn't expect, there are
  2473.             limitations to batch operations.  Here are some ways to get
  2474.             around those limitations:
  2475.             
  2476.             GETTING KEYSTROKES FROM EXTERNAL FILES
  2477.             
  2478.             One of the major limitations of a PC/MSDOS batch file is the
  2479.             inability to insert keystrokes into the batch file from the
  2480.             keyboard.  You can't stop a batch file, ask for user input,
  2481.             then continue with the execution of the batch file.  There
  2482.             are many times when you might want to do just that.
  2483.             
  2484.             PC/MSDOS has several commands which insist on user input.
  2485.             FORMAT, DISKCOPY, and DEL *.* are three of those commands.
  2486.             If your goal is complete automation of a command with batch
  2487.             files, these three operations will stall your batch file
  2488.             until you type a letter.
  2489.             
  2490.             Fortunately, there's a way to bypass this limitation.  All
  2491.             you need to do is create an external ASCII file which
  2492.             contains the keystroke.  Here's a good example:
  2493.             
  2494.             In my own work, I often place files in a directory on my
  2495.             hard disk, called C:\TEMP.  Once I'm finished working with
  2496.             those files, I want to delete them from the disk.  To do
  2497.             this means using the DEL *.* command.  PC/MSDOS, however,
  2498.             insists that I confirm the command by typing a Y.  If I give
  2499.             the command from a batch file, I still have to type the
  2500.             letter.
  2501.             
  2502.  
  2503.  
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.             Campbell -- Batch Power          Page 39
  2513.  
  2514.  
  2515.             To get around this problem, you can create a file which
  2516.             contains just the letter, Y and a carriage return.  I call
  2517.             the file YES.ASC.  Create this file by entering the
  2518.             keystrokes shown below:
  2519.             
  2520.             COPY CON YES.ASC
  2521.             Y <Enter>
  2522.             F6 <Enter>
  2523.             
  2524.             With that file stored on the disk, you can tell a batch file
  2525.             to take its input from the file and send it to any program
  2526.             called by the batch file.  Using the example above, here's a
  2527.             batch file, named KILLTEMP.BAT, which deletes all files from
  2528.             the directory C:\TEMP:
  2529.             
  2530.             ECHO OFF
  2531.             CLS
  2532.             DEL C:\TEMP\*.* <YES.ASC
  2533.             
  2534.             Create this file, using either the COPY CON command, or your
  2535.             text editor.  Substitute a directory name which applies to
  2536.             your computer for the one shown here.
  2537.             
  2538.             This batch file works by using redirection.  The "less than"
  2539.             symbol (<) tells PC/MSDOS to take directions from the file,
  2540.             YES.ASC rather than from the keyboard.  When the command DEL
  2541.             *.* gives the message "Are you sure (Y/N)," it sees the
  2542.             character "Y" included in the YES.ASC file, and thinks
  2543.             you've typed the letter on the keyboard.
  2544.             
  2545.             You can use this technique with any DOS command which asks
  2546.             for a confirmation from the user.  Be very careful, however,
  2547.             not to use the method if there is any danger of deleting
  2548.             important files.
  2549.             
  2550.             External text files can be used to create all sorts of
  2551.             useful DOS utilities.  Take the FORMAT command, for example.
  2552.             This program in DOS requires user keystrokes which slow down
  2553.             the process of formatting new floppy disks.
  2554.             
  2555.             If you hate the job of formatting a pile of floppies, you
  2556.             can create a disk formatting utility which will format
  2557.             floppy disks continuously, prompting you to insert a new
  2558.             floppy disk and press a key.
  2559.             
  2560.             To make this batch file work, you need to create a very
  2561.             short text file which contains the keystrokes needed for the
  2562.             PC-MSDOS FORMAT.COM program.  Call this file RESPONSE.ASC,
  2563.             and create it with the following commands:
  2564.             
  2565.             COPY CON RESPONSE.ASC <Enter>
  2566.             <Enter>
  2567.             N <Enter>
  2568.             F6 <Enter>
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.             Campbell -- Batch Power          Page 40
  2579.  
  2580.  
  2581.             
  2582.             Once you've created that file, you can set up a .BAT file to
  2583.             format diskettes continuously.  Since this file is rather
  2584.             long and complex, I suggest using your text editor or word
  2585.             processor to create the file.  Remember to save the file as
  2586.             a pure ASCII file.  Call this file CFORMAT.BAT.
  2587.             
  2588.             ECHO OFF
  2589.             IF .%1 ==. GOTO NOPARM
  2590.             IF %1 == c: GOTO NOHARD
  2591.             IF %1 == C: GOTO NOHARD
  2592.             CLS
  2593.             GOTO START
  2594.             :START
  2595.             ECHO Alt+255* 
  2596.             ECHO COMPUTER SHOPPER'S CONTINUOUS FORMAT UTILITY
  2597.             ECHO Alt+255* 
  2598.             ECHO Alt+255* 
  2599.             ECHO Alt+7*
  2600.             Echo Insert a new disk in drive %1 or press Ctrl+Break
  2601.             PAUSE
  2602.             CLS
  2603.             ECHO Alt+255*
  2604.             ECHO Alt+255*
  2605.             ECHO Alt+255*
  2606.             ECHO Now formatting....do not disturb disk in drive %1!
  2607.             FORMAT <RESPONSE.ASC %1 >NUL
  2608.             GOTO RETURN
  2609.             :NOPARM
  2610.             ECHO Alt+255*
  2611.             ECHO Alt+255*
  2612.             ECHO YOU MUST ENTER A DRIVE NAME.   EXAMPLE:(CFORMAT A:)
  2613.             PAUSE
  2614.             GOTO QUIT
  2615.             :HARD
  2616.             ECHO Alt+255*
  2617.             ECHO Alt+255*
  2618.             ECHO YOU CANNOT FORMAT A HARD DISK WITH THIS UTILITY.
  2619.             ECHO NOW RETURNING TO DOS....
  2620.             PAUSE
  2621.             GOTO QUIT
  2622.             :RETURN
  2623.             GOTO START
  2624.             :QUIT
  2625.             CLS
  2626.             
  2627.             * Hold down the <Alt> key while you type the number on the
  2628.             numeric keypad.
  2629.             
  2630.             
  2631.             This batch file uses many of the techniques presented in
  2632.             earlier parts of this series, including replaceable
  2633.             parameters, subroutines, and conditional branching.  It also
  2634.             uses the RESPONSE.ASC file to feed responses to the
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.             Campbell -- Batch Power          Page 41
  2645.  
  2646.  
  2647.             FORMAT.COM program.  The line which reads, FORMAT
  2648.             <RESPONSE.ASC %1 >NUL, is the key to this utility.  It calls
  2649.             the DOS FORMAT routine, then directs the program to take its
  2650.             responses from the text file you created.  Finally, the >NUL
  2651.             at the end of the line keeps the normal screen messages from
  2652.             FORMAT.COM off the screen.
  2653.             
  2654.             To use this program, copy CFORMAT.BAT and RESPONSE.ASC to
  2655.             the disk or directory which contains FORMAT.COM.  When you
  2656.             give the command, CFORMAT, add the drive name for your
  2657.             floppy disks.  If you don't include a drive name in your
  2658.             command, the program will abort and remind you.  If you
  2659.             specify drive C:, the batch file branches to the :NOHARD
  2660.             subroutine and aborts with a warning.
  2661.             
  2662.             The utility formats the disk, then returns to the beginning,
  2663.             beeps to remind you to change disks, and formats the next
  2664.             disk when you press a key.
  2665.             
  2666.             If you have a hard disk drive and two floppy drives, another
  2667.             version of this file can format disks in both drives,
  2668.             speeding up the process even further.  Create this file in
  2669.             the same way, but name it CFORMAT2.BAT.
  2670.             
  2671.             ECHO OFF
  2672.             CLS
  2673.             goto START
  2674.             :START
  2675.             CLS
  2676.             ECHO Alt+255* 
  2677.             ECHO Alt+255*
  2678.             ECHO COMPUTER SHOPPER'S CONTINUOUS FORMAT UTILITY
  2679.             ECHO Alt+255*
  2680.             ECHO Alt+7*
  2681.             ECHO Be sure to turn your TURBO mode off. 
  2682.             ECHO Alt+255*
  2683.             ECHO ECHO Insert new disks in drives A: and B:
  2684.             ECHO Alt+255* 
  2685.             ECHO To exit, press Ctrl+Break.
  2686.             PAUSE
  2687.             CLS
  2688.             ECHO Alt+255* 
  2689.             ECHO Alt+255* 
  2690.             ECHO Alt+255* 
  2691.             ECHO Now formatting....do not disturb disk in drive A:
  2692.             FORMAT <RESPONSE.ASC A: >NUL
  2693.             ECHO Now formatting....do not disturb disk in drive B:
  2694.             FORMAT <RESPONSE.ASC B: >NUL
  2695.             GOTO RETURN
  2696.             :RETURN
  2697.             GOTO START
  2698.             :QUIT
  2699.             CLS
  2700.             
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.             Campbell -- Batch Power          Page 42
  2711.  
  2712.  
  2713.             * Hold down the <Alt> key while you type the number on the
  2714.             numeric keypad.
  2715.             
  2716.             This file works in the same way, but automatically formats
  2717.             blank disks in both drive A: and drive B:. Each time the
  2718.             routine runs, it beeps to remind you to change disks.  I
  2719.             timed this routine, and it saves about 30% of the normal
  2720.             disk formatting time.
  2721.             
  2722.             You can use the same redirection technique to automate other
  2723.             utility programs which require keyboard input.  Try writing
  2724.             your own batch file to make the DISKCOPY command run
  2725.             continuously.  You'll need to write a text file, containing
  2726.             the keystrokes needed for that command, plus a batch file
  2727.             similar to the ones used for the FORMAT command.
  2728.             
  2729.             CREATING BATCH FILE PRESENTATIONS AND DEMOS
  2730.             
  2731.             Since batch files can automate many functions on your PC,
  2732.             creating demos and presentations is a natural use for these
  2733.             PC-MSDOS programs.
  2734.             
  2735.             A presentation or demo is typically a series of screens,
  2736.             displayed in order.  Using batch files to make the process
  2737.             automatic can let you concentrate on your presentation, and
  2738.             not on operating the PC.
  2739.             
  2740.             The first step in creating a demo is to create the screens
  2741.             you want to display.  Use your word processor or text editor
  2742.             to create as many screens as you like.  If you use Word
  2743.             Perfect or another program which can do line drawing and
  2744.             boxes, you can enhance these screens.  Many word processors
  2745.             can also use the <ALT>+numeric keypad technique to display
  2746.             extended ASCII characters, adding even more visual
  2747.             possibilities.
  2748.             
  2749.             Keep each screen down to 24 lines of text or less, so the
  2750.             whole screen can be displayed without scrolling.  Save your
  2751.             screens in ASCII format, naming them SCREEN1.TXT,
  2752.             SCREEN2.TXT, etc.  Number the files in the order you want to
  2753.             follow with your demo or presentation.
  2754.             
  2755.             Now, create the batch file you'll use to display your
  2756.             screens.  Call it DEMO.BAT, or any other name you like.
  2757.             Again, use your text editor or word processor to create the
  2758.             file.  Leave out the  REM commands and messages when you
  2759.             create the file.
  2760.             
  2761.             ECHO OFF
  2762.             CLS
  2763.             PROMPT Alt+255 REM Eliminates the DOS prompt.
  2764.             TYPE SCREEN1.TXT
  2765.             PAUSE>NUL  REM Shuts off the "Press a key" message.
  2766.             CLS
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.             Campbell -- Batch Power          Page 43
  2777.  
  2778.  
  2779.             TYPE SCREEN2.TXT
  2780.             PAUSE>NUL
  2781.             CLS
  2782.             TYPE SCREEN3.TXT
  2783.             .
  2784.             .
  2785.             .
  2786.             .
  2787.             TYPE SCREEN(n)
  2788.             CLS
  2789.             PROMPT REM Restores the dos prompt.
  2790.             
  2791.             Expand this batch file to include all of your presentation
  2792.             screens.  When you run DEMO.BAT, it will clear the screen,
  2793.             turn off the DOS prompt and load the first screen.  To
  2794.             change screens, just press any key on the keyboard.  The
  2795.             screen will clear and the next screen will appear.
  2796.             
  2797.             You can use the same program to create presentations for
  2798.             other users, as well.  Just leave the >NUL off the PAUSE
  2799.             lines in the batch file.  Now you can mail a disk containing
  2800.             your demo to another user.  When that user types the
  2801.             command, DEMO, your screens will display, with the line,
  2802.             "Strike a key when ready," at the bottom of each screen to
  2803.             prompt the user for a keystroke.  Even unskilled PC users
  2804.             won't have any trouble displaying your demo with this
  2805.             system.
  2806.             
  2807.             You'll find other uses for this presentation system.  I use
  2808.             it for displaying the documentation for shareware programs,
  2809.             and for sending letters and other documents to PC users.
  2810.             
  2811.             BATCH FILE EXTENSION SOFTWARE
  2812.             
  2813.             There are a number of commercial, public domain, and
  2814.             shareware programs designed to enhance your use of batch
  2815.             programming.  Using these external programs, you can add
  2816.             even more power to your batch files.  You may already have
  2817.             one or more such programs in your software library.  Here's
  2818.             a brief rundown on some of the best:
  2819.             
  2820.             
  2821.             THE NORTON UTILITIES
  2822.             
  2823.             This powerful collection of utilities contains several
  2824.             programs design to enhance your batch operations.  If you
  2825.             have this software, try out the following programs from the
  2826.             collection:
  2827.             
  2828.             ASK:  This program does what DOS can't do, accepting
  2829.             keyboard input from users during the execution of a batch
  2830.             file.  Especially useful in batch file menus, like the ones
  2831.             described in the first part of this series, ASK allows you
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.             Campbell -- Batch Power          Page 44
  2843.  
  2844.  
  2845.             to get a keystroke, then branch accordingly. This eliminates
  2846.             the need for additional batch files to call programs.
  2847.             
  2848.             BEEP: While you can cause your PC to beep in batch using the
  2849.             ECHO Ctrl-G command, Norton's BEEP command allows you to
  2850.             specify what kind of tone you get.  You can even create
  2851.             files to play simple tunes using this command.
  2852.             
  2853.             SA: Short for Screen Attributes, this program allows you to
  2854.             alter your computer's screen characteristics.  You can set
  2855.             up screen colors and other attributes by including this
  2856.             command, plus parameters in your batch files.  This one is
  2857.             especially useful for the presentation system discussed
  2858.             above.
  2859.             
  2860.             For more information on THE NORTON UTILITIES, contact Peter
  2861.             Norton Computing, Inc., 2210 Wilshire Blvd., #186, Santa
  2862.             Monica, CA 90403.  Phone: (800) 451-0303, Ext. 40.
  2863.             
  2864.             
  2865.             EXTENDED BATCH LANGUAGE
  2866.             
  2867.             This is a shareware program, designed specifically to
  2868.             increase the power of your batch files.  Using it, you can
  2869.             accept user input, perform arithmetic functions, search for
  2870.             files, and control the appearance of your computer's screen,
  2871.             or use many more of the program's functions. This program is
  2872.             a complete programming language in itself.
  2873.             
  2874.             If you're serious about batch programming, this program is a
  2875.             must for your library.  Like all shareware, you're free to
  2876.             try it out without charge.  The author requests a
  2877.             registration fee of $49 if you continue to use the program.
  2878.             That fee brings you additional functions and a complete
  2879.             manual.
  2880.             
  2881.             EXTENDED BATCH LANGUAGE is available for downloading on
  2882.             GEnie and Compuserve, and can be found in the catalogs of
  2883.             most shareware distributors.  It's also available directly
  2884.             from Seaware Corp., P.O. Box 1656, Delray Beach, FL 33444,
  2885.             Phone: (305) 392-2046.
  2886.             
  2887.             
  2888.             FSTSCRN2
  2889.             
  2890.             This public domain program performs a very useful function.
  2891.             It converts an ASCII file, no more than 24 lines long, into
  2892.             a .COM file.  By giving the name of the file as a command,
  2893.             you cause it to display on your monitor.
  2894.             
  2895.             What makes this program exciting is the way these converted
  2896.             ASCII screens pop onto the monitor almost instantly.  Use
  2897.             this program for menu screens, help screens, and screens
  2898.             used in the presentation system described above.
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.             Campbell -- Batch Power          Page 45
  2909.  
  2910.  
  2911.             
  2912.             Rather than displaying the screen with the TYPE command,
  2913.             just give the screen's filename as a command and you have
  2914.             instant response.  FSTSCRN2 can add a professional look to
  2915.             your batch files.
  2916.             
  2917.             Download the program from CompuServe or GEnie.  It's also
  2918.             available on many local BBS systems.
  2919.             
  2920.             THEDRAW
  2921.             
  2922.             Designing attractive screens can be a problem.  Using a word
  2923.             processor, especially when you want to include extended
  2924.             ASCII characters for simple graphics, can be a complicated
  2925.             process.
  2926.             
  2927.             THEDRAW is designed to solve just that problem.  Written by
  2928.             California programmer, Ian Davis, it is a complete screen
  2929.             design utility.  Using this program, you can create complex
  2930.             and attractive screens for menus, presentations, or demos --
  2931.             and you can do it quickly.
  2932.             
  2933.             The program even allows you to add color changes within your
  2934.             screen and, using ANSI.SYS in your CONFIG.SYS file, you can
  2935.             even create animated screens.  THEDRAW screens are displayed
  2936.             with the TYPE command.
  2937.             
  2938.             Available on CompuServe, GEnie, and from most shareware
  2939.             distributors, the program is shareware, with a registration
  2940.             fee of $10.  Contact the author directly at TheSoft
  2941.             Programming Services, 1929 Whitecliff Court, Walnut Creek,
  2942.             CA  94596.
  2943.             
  2944.             
  2945.             BOOTS
  2946.             
  2947.             This is a collection of three public domain utilities, which
  2948.             you can use in batch files to control booting your PC.
  2949.             WARMBOOT.COM simulates the <Ctrl>+<Alt>+<Del> keystroke
  2950.             combination and causes a warm boot of your PC.
  2951.             
  2952.             COLDBOOT.COM, the second program, simulates a cold boot.
  2953.             Instead of hitting the reset or power switch, you can reboot
  2954.             by giving the command, COLDBOOT.
  2955.             
  2956.             BOOTNOT.COM prevents a user from rebooting with the
  2957.             <Ctrl>+<Alt>+<Del> key combination.  This is very useful,
  2958.             especially if inexperienced users might destroy data on your
  2959.             PC by accident.
  2960.             
  2961.             The other two programs can be included in batch files
  2962.             whenever you need to reboot your system.  One possible use
  2963.             would be to remove memory-resident programs.  I use it this
  2964.  
  2965.  
  2966.  
  2967.  
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.             Campbell -- Batch Power          Page 46
  2975.  
  2976.  
  2977.             way to remove a memory-resident program or a RAM disk which
  2978.             might interfere with another program.
  2979.             
  2980.             BOOTS is available on GEnie and CompuServe for downloading.
  2981.             
  2982.             
  2983.             FIXBEEP
  2984.             
  2985.             Most users are quickly annoyed with the monotonous beep
  2986.             produced by their computers.  If you've ever dreamed about
  2987.             replacing that beep with another sound, FIXBEEP is the
  2988.             answer.
  2989.             
  2990.             Written by Mike Blaszczak, FIXBEEP, allows you to change
  2991.             that sound to anything you want.  The program is shareware,
  2992.             but the registration fee is only $5.
  2993.             
  2994.             Use fixbeep in your batch files to change the beep tone.
  2995.             You can alter the tone to signal different operations in
  2996.             your file, signalling the user to take action.  For example,
  2997.             to change the normal beep to a short, high-pitched sound,
  2998.             include the following command in any batch file.
  2999.             
  3000.             FIXBEEP /F3000 /D50
  3001.             
  3002.             This command would produce a tone with a pitch of 3000
  3003.             hertz, lasting for half a second.
  3004.             
  3005.             FIXBEEP is available on The Source, CompuServe, and GEnie,
  3006.             as well as from the author.  Contact Mike "Nifty James"
  3007.             Blaszczak, 112 Verlinden Drive, Monroeville, PA  15146.
  3008.             
  3009.             
  3010.             TOGGLE
  3011.             
  3012.             There are many occasions when you might want to turn the
  3013.             CapsLock or NumLock function on or off from a batch file.
  3014.             The two programs in TOGGLE, CAPLOCK.COM and NUMLOCK.COM,
  3015.             allow you to do just that.
  3016.             
  3017.             I use NUMLOCK.COM in the batch files which call my
  3018.             spreadsheet and accounting programs.  It saves me from the
  3019.             mistakes I usually make by forgetting to press the NumLock
  3020.             key.
  3021.             
  3022.             TOGGLE is in the public domain, and is available for
  3023.             downloading on GEnie and Compuserve.
  3024.             
  3025.             
  3026.             E88
  3027.             
  3028.             If your word processor can't save files in ASCII format, or
  3029.             if you would just like to have a simple, fast text editor
  3030.  
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.             Campbell -- Batch Power          Page 47
  3041.  
  3042.  
  3043.             for creating and altering batch files, E88 may be just the
  3044.             editor you need.
  3045.             
  3046.             It produces pure ASCII files, and has a text search
  3047.             function, along with block moves and other editing functions
  3048.             you'll find useful for batch programming.
  3049.             
  3050.             E88 is easy to learn, fast, and, for programming purposes,
  3051.             is often better than a full-fledged word processor.  The
  3052.             program is shareware, but the author asks only $10 as a
  3053.             registration fee.
  3054.             
  3055.             E88 is available for downloading from GEnie and CompuServe,
  3056.             or you can contact the author at M.R.E. Software, 150 Jones
  3057.             St., West Point, MS  39773
  3058.             
  3059.             
  3060.             SPECIAL OFFER
  3061.             
  3062.             As a service to the readers of this series on batch files,
  3063.             I'll be happy to send readers a disk containing all the
  3064.             public domain and shareware programs mentioned above.  To
  3065.             cover the costs of copying and mailing, send $7.50 for a
  3066.             5.25" floppy disk or $10 for a 3.5" disk to:
  3067.             
  3068.             George Campbell
  3069.             1472 Sixth St.
  3070.             Los Osos, CA  93402
  3071.             
  3072.             Be sure to mention the batch file articles, and specify your
  3073.             disk size.  All of these programs contain their own
  3074.             documentation in an ASCII file which you can copy to your
  3075.             printer.  If you use these programs regularly, please honor
  3076.             the shareware concept by sending the registration fee to the
  3077.             authors who request it.
  3078.             
  3079.             
  3080.             TIPS FOR EFFECTIVE BATCH PROGRAMMING
  3081.             
  3082.             1. Plan your batch files before you begin to write them.
  3083.             Make a list of the functions you want to perform, then begin
  3084.             creating the file.  Always give batch files easy-to-remember
  3085.             filenames to avoid errors.
  3086.             
  3087.             2. Include lines which use the ECHO command to print screen
  3088.             messages.  Users, yourself included, will benefit from
  3089.             screen messages which explain what's going on during batch
  3090.             file execution.
  3091.             
  3092.             3. In any batch file which uses replaceable parameters,
  3093.             include an IF line to check whether or not a parameter was
  3094.             given with the command.  If not, GOTO a subroutine which
  3095.             explains the correct syntax for the batch file.  The
  3096.             CFORMAT.BAT in this article is a good example.
  3097.  
  3098.  
  3099.  
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.             Campbell -- Batch Power          Page 48
  3107.  
  3108.  
  3109.             
  3110.             4. If you have a hard disk, create a directory called
  3111.             C:\BATCH, and store all your batch files in that directory.
  3112.             If you include the directory in your PATH command, you'll be
  3113.             able to access your batch files while you're in any
  3114.             directory on your hard disk.  Here's a sample PATH command:
  3115.             
  3116.             PATH = C:\;C:\DOS;C:\BATCH
  3117.             
  3118.             Thanks to reader Roger Paulson for reminding me of this
  3119.             important tip.
  3120.             
  3121.             5. You can give the command to execute another batch file in
  3122.             any batch file.  To return to the original batch file, just
  3123.             give its filename as the last line of your second file.  You
  3124.             can't call the current batch file, however, from within that
  3125.             file.
  3126.             
  3127.             6. Use the <ALT>+255 technique to create blank lines with
  3128.             the ECHO command, and to eliminate the DOS prompt with the
  3129.             PROMPT command.  This works with all versions of DOS, from
  3130.             2.0 on.  Be sure to leave a space between the command and
  3131.             the key combination, and always use the number pad to enter
  3132.             the numbers.
  3133.             
  3134.             Note:  You can also insert any extended ASCII character,
  3135.             such as the ASCII graphics characters, using the same
  3136.             technique.  Just substitute the correct ASCII code in place
  3137.             of the 255 code for a blank character.  You'll find a chart
  3138.             showing these codes in your DOS manual.
  3139.             
  3140.             7.  Don't use the DOS redirection characters (< and >) in
  3141.             ECHO, PROMPT, or PAUSE lines in your batch files.  DOS sees
  3142.             them as part of a command and will respond with the "Bad
  3143.             command or filename" error message.  Substitute brackets
  3144.             ([]) or curly brackets ({}) instead.
  3145.             
  3146.             8.  When testing new batch files, you'll often encounter
  3147.             error messages.  These usually mean you've misspelled a
  3148.             command or left out a space after ECHO, PROMPT, or PAUSE
  3149.             commands.  Check for these errors first.
  3150.             
  3151.             9.  Memory-resident programs sometimes conflict with each
  3152.             other.  If you encounter unusual problems after adding a
  3153.             memory-resident program's command to an AUTOEXEC.BAT file,
  3154.             try changing the order of the programs.  You may have to try
  3155.             several orders to make your memory-resident programs
  3156.             cooperate.
  3157.             
  3158.             10.  Finally, experiment with batch files.  Anytime you find
  3159.             yourself typing the same series of DOS commands, consider
  3160.             creating a batch file to automate your computing.
  3161.                                           
  3162.  
  3163.  
  3164.  
  3165.  
  3166.  
  3167.  
  3168.  
  3169.